×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    63

    Correct way of QThread usage

    hi,
    happy new year.

    I have a question about QThread. This blog post http://labs.qt.nokia.com/2010/06/17/...oing-it-wrong/ 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();

    but
    a) Progress dialog is never shown
    b) dbInitFinished is never called

    What am i doing wrong?

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Correct way of QThread usage

    What am i doing wrong?
    Well, you read that guy's tyrade, for one. Better to use the pattern in the QThread documentation.

  3. #3
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    63

    Re: Correct way of QThread usage

    This blog is written by the Qt development team and covers the development of Qt and related projects.
    Bradley T Hughes. Senior Software Engineer. Leader of the Qt Platform Team.
    So .. back to my original question, what is incorrect? Because i don't understand why i need to create classes for new threads.

Similar Threads

  1. QNetworkAccessManager and Qthread
    By Fillinger in forum Qt
    Replies: 12
    Last Post: 2010-09-25, 21:18
  2. Replies: 1
    Last Post: 2010-08-12, 10:27
  3. QThread and MainWindow (Qt designer)
    By darksoul_e in forum Qt
    Replies: 11
    Last Post: 2010-05-18, 14:12
  4. usage of CArrayFixFlat is correct or not
    By swapnil_mahajan in forum Symbian
    Replies: 8
    Last Post: 2009-07-21, 05:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×