Results 1 to 4 of 4

Thread: how to enable a timer in a non-gui thread?

  1. #1
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    3

    Default how to enable a timer in a non-gui thread?

    I have a non-gui thread to process db files , and I want a slot located in this thread to check the db files every a threshold assigned by a QTimer. the slot will emit a signal to post information to a gui thread to show db files' status. but the slot connected to this timer won't work in this thread.
    I don't want to use such soluton:
    this timer was located in the gui thread and was connected a slot located in that non-gui thread.

    how can I enable this timer in such non-gui thread in some other solution?

    any help will be appreciated!
    Last edited by zeopha; 3rd August 2008 at 21:05.

  2. #2
    Join Date
    Jul 2008
    Location
    Netherlands
    Posts
    33
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to enable a timer in a non-gui thread?

    I'm not sure what your problem is?
    Is it that a QTimer in the GUI thread is not triggering the slot in the DB thread?
    Can you maybe post some code that clarifies what is not working and/or the solution you don't want to use?

  3. The following user says thank you to lvi for this useful post:

    zeopha (5th August 2008)

  4. #3
    Join Date
    Nov 2007
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: how to enable a timer in a non-gui thread?

    Zeopha, your problem more than likely is that you forgot to call exec() in your thread's run function. Without calling exec, the thread won't have an event loop, which is necessary for the use of QTimer.
    Read the documentation for QTimer and QThread for more info.

    I hope that answers your question.

  5. The following user says thank you to Khal Drogo for this useful post:

    zeopha (5th August 2008)

  6. #4
    Join Date
    Aug 2008
    Posts
    5
    Thanks
    3

    Default Re: how to enable a timer in a non-gui thread?

    to Lvi:
    a timer located in the main gui widget will trigger the slot in another qthread. but I just think that the timer should not be located in the gui

    to:Khal Drogo

    U r right. I had forgetten to execute the exec() in the run function of thread. So am I stupid!!!

    thanks to Liv and Khal Drogo !

Similar Threads

  1. QSocketNotifier can not enable from an other thread.
    By dabiabilus in forum Qt Programming
    Replies: 4
    Last Post: 5th August 2008, 14:31
  2. Thread, Timer and Socket. Comuication problem
    By ^NyAw^ in forum Qt Programming
    Replies: 6
    Last Post: 17th January 2008, 17:48
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 07:13
  4. Replies: 10
    Last Post: 20th March 2007, 23:19
  5. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 01:49

Tags for this Thread

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.