| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
On Friday 30 November 2007, Stephen Collyer wrote:
> 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 :-)
If you are using threads you probably know this already ... but... be carefull
of calling non-thread safe methods of the global instance without proper
locking.
> void run()
> {
> QCoreApplication app(..)
> QSqlDatabase db = QCoreApplication::addDatabase(..)
> }
For this you can use QSqlDatabase::addDatabase(...) witch IS thread safe.
happy coding
--
[ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.