×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    61

    QThread sleep maximum

    Hey! I've a class that is subclassing QThread and when I use a small sleep value like sleep(5) it works. If I do a sleep(1000) it doesn't even stop. Why is this?

  2. #2
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: QThread sleep maximum

    Hi,

    How are you trying to stop it, are you calling quit or exit? can you give a small piece, may be the run() part

  3. #3
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,087

    Re: QThread sleep maximum

    I think stop here refers to sleep only (i.e. if sleep time passed is that much, the thread even does not sleeps)

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    61

    Re: QThread sleep maximum

    it is like vineet.jain said. The thread does not sleep

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: QThread sleep maximum

    Hi,

    I tried running the same on QT simulator using QT SDK1.1.4 in ubuntu,

    it works fine for me

    #include <QtCore/QCoreApplication>
    #include <QThread>
    #include <QDebug>
    class MyThread : public QThread {

    public:

    virtual void run();

    };

    void MyThread::run()
    {
    qDebug() << "I am here";
    for( int count = 0; count < 20; count++ ) {
    QThread::sleep(1000);
    //QThread::sleep(10);
    //sleep(1000);
    qDebug() << "Ping!" ;
    }

    }

    int main(int argc, char *argv[])
    {
    QCoreApplication a1(argc, argv);
    MyThread *a = new MyThread;

    qDebug() << "I am here in main";
    a->start();

    a1.exec();
    }

    All the sleep methods including the commented ones run fine. That is the thread enters into long sleep mode as expected.

  6. #6
    Registered User
    Join Date
    Feb 2012
    Posts
    61

    Re: QThread sleep maximum

    I am using Qt Symbian 4.6.3 ( sorry that i didn't mention that). The application logic is:


    main -> Launches Thread A -> Launches Thread A1
    ----------------------------------> Launches Thread A2
    ----------------------------------> Launches Thread A3

    My sleep code is on those Threads Ax
    Last edited by apinho; 2012-02-17 at 11:42.

  7. #7
    Regular Contributor
    Join Date
    May 2010
    Posts
    362

    Re: QThread sleep maximum

    Are you sure the sleep(5) does work?

  8. #8
    Registered User
    Join Date
    Feb 2012
    Posts
    61

    Re: QThread sleep maximum

    Yes it does work. I've tried to find the maximum value and I get for the first thread I launch is 2147. Then for the other threads keeps changing . Am I launching threads in a wrong way or what?

  9. #9
    Regular Contributor
    Join Date
    May 2010
    Posts
    362

    Re: QThread sleep maximum

    The current way of using QThreads is not to actually subclass this.
    I know this seems contradictory, since most official resources still tell you to do so.

    Please search for "Subclassing no longer recommended way of using QThread" in:
    http://developer.qt.nokia.com/doc/qt-4.7/qthread.html

    Also: http://labs.qt.nokia.com/2010/06/17/...oing-it-wrong/

  10. #10
    Registered User
    Join Date
    Feb 2012
    Posts
    61

    Re: QThread sleep maximum

    Ok, I just wanted to launch a simple thread that would execute the run() method. Why do I need signals and connects? Do I have to emit a signal for my thread to invoque its run() method?

  11. #11
    Registered User
    Join Date
    Feb 2012
    Posts
    61

    Re: QThread sleep maximum

    teemup thanks i was able to fix it by changing my threads implementation... and instead of a sleep i've used a QTimer to run my code.

  12. #12
    Regular Contributor
    Join Date
    May 2010
    Posts
    362

    Re: QThread sleep maximum

    That is a good solution and good thing you managed to get it working!

Similar Threads

  1. Using QHttp with Qthread
    By schroffi in forum Qt
    Replies: 2
    Last Post: 2011-06-09, 16:39
  2. Correct way of QThread usage
    By gerasalus in forum Qt
    Replies: 2
    Last Post: 2011-01-03, 16:12
  3. QNetworkAccessManager and Qthread
    By Fillinger in forum Qt
    Replies: 12
    Last Post: 2010-09-25, 21:18
  4. Replies: 1
    Last Post: 2010-08-12, 10:27
  5. QThread and MainWindow (Qt designer)
    By darksoul_e in forum Qt
    Replies: 11
    Last Post: 2010-05-18, 14:12

Posting Permissions

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