Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, November 2007
Creating QCoreApplication object in threads ?


Message 1 in thread

I want to create a QSqlDatabase object in various threads.
To do so, I need a QCoreApplication object. However, I can't
figure out how to create a QCoreApplication object in a thread.
The only constructor listed for this class take argc and argv,
which won't, in general, be available. I was assuming that
QCoreApplication would be created in the run() method so:

void run()
{
    QCoreApplication app(..)
    QSqlDatabase db = QCoreApplication::addDatabase(..)

}

but that doesn't seem right. Can someone explain what
I'm missing here. I can't quite see how this is all going
to hang together. Where, in general, does a thread get its
QCoreApplication object from ?

-- 
 [ signature omitted ] 

Message 2 in thread

Stephen Collyer wrote:
>Where, in general, does a thread get its
>QCoreApplication object from ?

The global one, via QCoreApplication::instance().

You're supposed to declare it in the main() function.

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

Thiago Macieira wrote:
> Stephen Collyer wrote:
>> Where, in general, does a thread get its
>> QCoreApplication object from ?
> 
> The global one, via QCoreApplication::instance().
> 
> You're supposed to declare it in the main() function.

Right, thanks. I understand now. You create one QCoreApplication
in main, and all the other threads pick it up via the instance
method when you call one of the static class methods.

I was confused before as I thought I had created a
QCoreApplication in main (which I had done, in fact;
unfortunately, that was in a different program to
the one I was running :-)

-- 
 [ signature omitted ]