Results 1 to 7 of 7

Thread: my SLOT not part of QThread

  1. #1
    Join Date
    Feb 2006
    Posts
    25
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default my SLOT not part of QThread

    Hello, I got the following problem.

    Qt Code:
    1. class mythread : public QThread
    2. {
    3. public:
    4. mythread();
    5. void run();
    6. public slots:
    7. void processpacket();
    8.  
    9. private:
    10. QTcpServer *tcpServer;
    11. };
    To copy to clipboard, switch view to plain text mode 

    inside mythread::run I have this

    Qt Code:
    1. connect(tcpServer, SIGNAL(newConnection()), this, SLOT(processpacket()));
    To copy to clipboard, switch view to plain text mode 

    everything compiles and builds but when I run it I get a
    Qt Code:
    1. Object::connect: No such slot QThread::processpacket().
    To copy to clipboard, switch view to plain text mode 

    and if I add Q_OBJECT as follows:

    Qt Code:
    1. class mythread : public Qthread
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. mythread();
    7. void run();
    8. public slots:
    9. void processpacket();
    10.  
    11. private:
    12. QTcpServer *tcpServer;
    13. };
    To copy to clipboard, switch view to plain text mode 

    I get the following error when compiling.:

    undefined reference to 'vtable for mythread'

    Any help in solving this issues is appreciated. Thanks in advanced

  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: my SLOT not part of QThread

    Re-run qmake after adding Q_OBJECT macro.
    J-P Nurmi

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

    freak (16th June 2006)

  4. #3
    Join Date
    Feb 2006
    Posts
    25
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: my SLOT not part of QThread

    Thanks Jpn, that solved both problems. Now i have a problem where the SLOT code is never executed. I send packets from my client machine but it does nothing. is the code shown above incorrect?

    Thanks in advanced

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: my SLOT not part of QThread

    Quote Originally Posted by freak
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(processpacket()));
    Beware that a QThread object and all objects created in its constructor live in a thread where that QThread instance was created, while all objects created in QThread::run() live in a newly created thread.

    This means that the above connection will be a queued connection and processpacket() won't be executed by the new thread. Either move those slots to some other object that you will create in QThread::run() or make that connection a direct one explicitly.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: my SLOT not part of QThread

    Quote Originally Posted by freak
    Now i have a problem where the SLOT code is never executed.
    Do you start the event loop in that new thread (i.e. do you invoke QThread::exec() in run() )?

  7. #6
    Join Date
    Feb 2006
    Posts
    25
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: my SLOT not part of QThread

    I do call exec() inside run.

    How do you make a connection explicitly?

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: my SLOT not part of QThread

    Quote Originally Posted by freak
    How do you make a connection explicitly?
    Qt Code:
    1. connect( tcpServer, SIGNAL( newConnection() ),
    2. this, SLOT( processpacket() ),
    3. Qt::DirectConnection );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QThread help please
    By munna in forum Newbie
    Replies: 14
    Last Post: 31st May 2006, 04:54
  2. Replies: 2
    Last Post: 4th May 2006, 19:17
  3. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51
  4. SLOT and QPushButton
    By mickey in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2006, 06:46
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.