Results 1 to 6 of 6

Thread: Problem about QTimer

  1. #1
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Problem about QTimer

    I have several classes in my program, one of them is the main GUI and other is an XML-RPC (from XML-RPC for C/C++) class that have several methods. All thinks goes ok, but when I start the QTimer in the GUI class from the XMLRPC clas it says "QTimer can't be stop/started from other thread". If I put signals and slots does nothing. WTF?

    Qt Code:
    1. cambiaTimer::cambiaTimer ( rssani_lite *rss, QObject *parent ) : QObject ( parent ),rpc_ani ( rss ) {
    2. connect ( this,SIGNAL ( cambiarTimer ( int ) ), rss, SLOT ( cambiaTimer ( int ) ) );
    3. }
    4.  
    5. void cambiaTimer::execute ( xmlrpc_c::paramList const& paramList,xmlrpc_c::value * const retvalP ) {
    6.  
    7. emit cambiarTimer ( 1 );
    8. std::cerr << "RPC llamada" << std::endl;
    9. *retvalP = xmlrpc_c::value_int ( 0 ) ;
    10. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void rssani_lite::cambiaTimer(int tiempo) {
    2. qDebug() << "Timer cambiado a : " << tiempo << endl;
    3. this->tiempo = tiempo;
    4. timer.start ( tiempo * 60 * 1000 );
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class rssani_lite : public QObject {
    2. Q_OBJECT
    3.  
    4. public:
    5. rssani_lite ( QObject* parent = 0);
    6. ~rssani_lite();
    7.  
    8. public slots:
    9. void cambiaTimer(int tiempo);
    10. ....
    11. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.
    Last edited by pawer; 21st January 2008 at 19:29.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem about QTimer

    Are you using QThread somewhere in your app?
    J-P Nurmi

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

    pawer (21st January 2008)

  4. #3
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem about QTimer

    No, I create 2 classes in main function:

    Qt Code:
    1. int main ( int argc, char **argv ) {
    2. QCoreApplication app(argc, argv);
    3. .....
    4. rssani_lite *rss = new rssani_lite();
    5. new rssxmlrpc(rss);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. rssxmlrpc:: rssxmlrpc ( rssani_lite *rss ) {
    2. ....
    3. xmlrpc_c::methodPtr const cambiaTimerP ( new cambiaTimer ( rss ) );
    4. ....
    5. myRegistry.addMethod ( "rssani.cambiaTimer", cambiaTimerP );
    6.  
    7. xmlrpc_c::serverAbyss myAbyssServer (
    8. myRegistry,
    9. 8080, // TCP port on which to listen
    10. "/tmp/xmlrpc_log" // Log file
    11. );
    12.  
    13. myAbyssServer.run();
    14. assert ( false );
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by pawer; 21st January 2008 at 19:12.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem about QTimer

    Maybe one of these two classes:
    Qt Code:
    1. rssani_lite *rss = new rssani_lite();
    2. new rssxmlrpc(rss);
    To copy to clipboard, switch view to plain text mode 
    starts a new thread? The effect you observe suggests rssani_lite is the one. The timer object is a member of the rssani_lite class but it does not live in the thread spawned by that class.

  6. The following user says thank you to wysota for this useful post:

    pawer (22nd January 2008)

  7. #5
    Join Date
    May 2007
    Posts
    9
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem about QTimer

    Qt Code:
    1. $ ./rssani_lite
    2. RPC llamada
    3. Timer cambiado a : 1
    4.  
    5. QObject::killTimer: timers cannot be stopped from another thread
    6. QObject::startTimer: timers cannot be started from another thread
    7. QObject::killTimer: timers cannot be stopped from another thread
    8. QObject::startTimer: timers cannot be started from another thread
    To copy to clipboard, switch view to plain text mode 

    This is the output if I call the method directly. I don't know the signal behaviour, because the slot is not called.

    Thanks for your answers.
    Last edited by pawer; 22nd January 2008 at 17:39.

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem about QTimer

    Signals and slots have nothing to do with it. You just have to start the timer from within the proper thread.

Similar Threads

  1. QTimer and QSqlDatabase Problem
    By smtgra011 in forum Qt Programming
    Replies: 6
    Last Post: 4th July 2007, 16:37
  2. QTimer problem
    By vv in forum Qt Programming
    Replies: 9
    Last Post: 3rd July 2007, 08:13
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. Qthread n QTimer Problem
    By quickNitin in forum Qt Programming
    Replies: 5
    Last Post: 8th June 2006, 14:12
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.