Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Interested in knowing the exact reasoning behind it!!!
Forum Updated to NodeBB v4.3 + New Features

Interested in knowing the exact reasoning behind it!!!

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 2.7k Views 1 Watching
  • 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 Offline
    F Offline
    feedmeqt
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

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

      ...
      }
      @

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rahul Das
        wrote on last edited by
        #3

        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


        Declaration of (Platform) independence.

        1 Reply Last reply
        0
        • BilbonSacquetB Offline
          BilbonSacquetB Offline
          BilbonSacquet
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved