Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Interested in knowing the exact reasoning behind it!!!

    General and Desktop
    4
    4
    2483
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      feedmeqt last edited by

      Hi,

      I'm interested in knowing the reason for this.

      @
      " QObject::connect: No such slot QThread::StopedServiceThread<> in MyThread.cpp"
      @

      Even though I tried to debug the QT4.7.4 framework, but couldn't come with any conclusion.
      @
      //MyThread.h

      #include <QThread>
      #include<qobject.h>

      class Mythread : public QThread
      {
      public:
      Mythread(QObject *parent = 0);
      ~Mythread();

      void setThreadFlag();
      void setDelay();
      void run();

      private:
      qint32 stopTheThread;

      public slots:
      void TerminateServiceThread();
      void StopedServiceThread();
      };

      //MyThread.cpp

      #include "Mythread.h"

      Mythread::Mythread(QObject *parent)
      : QThread(parent)
      {

      stopTheThread = false;
      QObject::connect(this, SIGNAL(finished()), this, SLOT(StopedServiceThread()));
      }

      Mythread::~Mythread()
      {

      }

      void Mythread::setThreadFlag() {
      stopTheThread = true;
      }

      void Mythread::StopedServiceThread() {
      printf("Thread stopped\n");
      }

      void Mythread::TerminateServiceThread() {

      printf("Thread Got terminated \n");

      }

      //main.cpp

      #include <QtCore/QCoreApplication>
      #include "Mythread.h"

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);

      Mythread obj;

      obj.start();

      obj.setDelay();

      obj.setThreadFlag();
      return a.exec();
      }
      @

      [edit: fixed typo in title, Eddy]
      [EDIT: code formatting for error output, Volker]

      1 Reply Last reply Reply Quote 0
      • C
        cincirin last edited by

        Your class should look like this :
        @
        class Mythread : public QThread
        {
        Q_OBJECT

        ...
        }
        @

        1 Reply Last reply Reply Quote 0
        • R
          Rahul Das last edited by

          Where is "Q_OBJECT":http://doc.qt.nokia.com/4.7/qobject.html#Q_OBJECT macro ?

          Edit : You need Q_OBJECT macro, so that MOC (meta Object Compiler) will do the necessary to implement signals and slots . Refer "Meta-Object system":http://doc.qt.nokia.com/4.7/metaobjects.html#meta-object-system


            Rahul Das
          

          1 Reply Last reply Reply Quote 0
          • BilbonSacquet
            BilbonSacquet last edited by

            The reason is simple if you don't have the Q_OBJECT macro, "the class will not be moc'ed":http://doc.qt.nokia.com/4.7/signalsandslots.html in moc_MyThread.cpp and the slots don't exist.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post