Correct way of QThread usage
hi,
happy new year.
I have a question about QThread. This blog post [url]http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/[/url] says that it is wrong to subclass QThread. O i'm trying to do it this way:
1) I have a MainWindow class with slot dbInitFinished
2) i have a class DbManager with slot init(), which is a "long" running operation, and need to be run in separate thread
My code looks like this:
[CODE]
dialog = new QProgressDialog();
dialog->setLabelText("Wait, db initing");
dialog->setMinimum(0);
dialog->setMaximum(0);
dialog->setWindowModality(Qt::WindowModal);
dialog->showMaximized();
dbManager = new DbManager();
QThread* t = new QThread();
connect(t,SIGNAL(started()),dbManager,SLOT(init()));
connect(t,SIGNAL(finished()),this,SLOT(dbInitFinished()), Qt::DirectConnection);
dbManager->moveToThread(t);
t->start();
[/CODE]
but
a) Progress dialog is never shown
b) dbInitFinished is never called
What am i doing wrong?
Re: Correct way of QThread usage
[QUOTE]What am i doing wrong?[/QUOTE]
Well, you read that guy's tyrade, for one. Better to use the pattern in the QThread documentation.
Re: Correct way of QThread usage
[QUOTE]This blog is written by the Qt development team and covers the development of Qt and related projects.[/QUOTE]
[QUOTE] Bradley T Hughes. Senior Software Engineer. Leader of the Qt Platform Team.[/QUOTE]
So .. back to my original question, what is incorrect? Because i don't understand why i need to create classes for new threads.