Results 1 to 3 of 3

Thread: how to change msleep seconds in QThread

  1. #1
    Join Date
    Jan 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to change msleep seconds in QThread

    hi All,

    i want to change my msleep seconds by QSlider.According to the value change in slider ,the seconds should be changed.

    Qt Code:
    1. class MyThread :public QThread
    2.  
    3. {
    4.  
    5. Q_OBJECT
    6.  
    7. private:
    8.  
    9. bool m_bToSuspend;
    10.  
    11. QWaitCondition m_waitCondt;
    12.  
    13. public :
    14.  
    15. QMutex mutex;
    16.  
    17. QWaitCondition wcCondition;
    18.  
    19. int count,iSeconds;
    20.  
    21. MyThread()
    22.  
    23. {
    24.  
    25. count=0;
    26.  
    27. m_bToSuspend=false;
    28.  
    29.  
    30. iSeconds=1000;
    31.  
    32. }
    33.  
    34. void run()
    35.  
    36. {
    37.  
    38. QMutex waitMutex;
    39.  
    40. //qDebug()<<"count : "<<count;
    41.  
    42. for (int i=0;i<count;)
    43.  
    44. {
    45.  
    46. msleep(iSeconds);
    47.  
    48. qDebug()<<iSeconds;
    49.  
    50. emit changeValue(i);
    51.  
    52. // pause the simulator
    53.  
    54. if (m_bToSuspend)
    55.  
    56. {
    57.  
    58. waitMutex.lock();
    59.  
    60. m_waitCondt.wait(&waitMutex);
    61.  
    62. waitMutex.unlock();
    63.  
    64. }
    65.  
    66. i+=3;
    67.  
    68. }
    69.  
    70. }
    71.  
    72. signals:
    73.  
    74. void changeValue(int i);
    75.  
    76. public slots:
    77.  
    78. void getCount (int pCount)
    79.  
    80. {
    81.  
    82. count=pCount;
    83.  
    84. }
    85.  
    86. void suspend();
    87.  
    88. void startThread();
    89.  
    90. void getTimer(int pval)
    91.  
    92. {
    93.  
    94. iSeconds=pval*100;
    95.  
    96. }
    97.  
    98. };
    To copy to clipboard, switch view to plain text mode 

    In this getTimer() slot is used by the slider control.
    connect(slider,SIGNAL(valuchanged(int)),thread,SLO T(getTimer()));
    The thread is started after creating a instance of the class MyThread;

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    509
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to change msleep seconds in QThread

    Hi, it should be
    Qt Code:
    1. connect(slider,SIGNAL(valueChanged(int)),thread,SLOT(getTimer(int)));
    To copy to clipboard, switch view to plain text mode 
    note the int in getTimer.

    Ginsengelf
    Last edited by Ginsengelf; 21st July 2010 at 10:59. Reason: reformatted to look better

  3. #3
    Join Date
    Jan 2009
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change msleep seconds in QThread

    hi Ginsengelf,

    iSeconds value is not updating in run event loop.While the thread is running i want to change the msleep seconds.

Similar Threads

  1. change QWidget from QThread classes
    By radeberger in forum Qt Programming
    Replies: 12
    Last Post: 30th May 2010, 19:45
  2. QThread under Windows XP - usleep(), msleep() problem
    By tungstrom in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2009, 17:04
  3. change QGraphicsView* in QThread
    By deca5423 in forum Qt Programming
    Replies: 4
    Last Post: 30th June 2009, 01:12
  4. problem with msleep
    By Reinexen in forum Newbie
    Replies: 3
    Last Post: 28th December 2007, 16:32
  5. QThread msleep precision
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2007, 23:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.