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. QObject::connect: No such slot error
Forum Updated to NodeBB v4.3 + New Features

QObject::connect: No such slot error

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 4.5k 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.
  • NiagarerN Offline
    NiagarerN Offline
    Niagarer
    wrote on last edited by
    #1

    Hey,
    I wrote the following code:

    void FunctionNodeDetailsForm::setUpEverything(){
        QWidget *dataInterfaceWidget = new QWidget;
        dataInterfaceWidget->setLayout(new QHBoxLayout);
    
        // NAME LINE EDIT
        QLineEdit *nameLineEdit = new QLineEdit();
        nameLineEdit->setText(di->displayName);
        dataInterfaceWidget->layout()->addWidget(nameLineEdit);
        connect(nameLineEdit, SIGNAL(textChanged(QString)),
                parentNode, SLOT(inputNameChanged(QString)));
    
        ui->inputs_widget->layout()->addWidget(dataInterfaceWidget);
    }
    

    parentNode is a object of the class FunctionNode :

    class FunctionNode : public Node
    {
    public:
        FunctionNode(GraphWidget *graphWidgetInput = nullptr,
                     int numberInput = -1,
                     FunctionNode *activeNodeInput = nullptr);
    
    public slots:
        void inputNameChanged(QString newName);
    };
    

    The class Node derives from QObject and I call Q_Object macro in the Node-class

    class Node : public QObject
    {
        Q_OBJECT
    ...
    

    But at runtime, I get this error when setUpEverything() is called:

    QObject::connect: No such slot Node::inputNameChanged(QString)
    

    I also ran qmake, cleaned and rebuilt. I can't find more sources of the error.
    Any ideas?
    Thanks for answers!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      FunctionNode class needs Q_OBJECT too ...

      NiagarerN 2 Replies Last reply
      2
      • M mpergand

        FunctionNode class needs Q_OBJECT too ...

        NiagarerN Offline
        NiagarerN Offline
        Niagarer
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • M mpergand

          FunctionNode class needs Q_OBJECT too ...

          NiagarerN Offline
          NiagarerN Offline
          Niagarer
          wrote on last edited by
          #4

          @mpergand
          Oh, nice, it worked! I didn't know that and it does not make really sence to me yet...
          I am interested, it would be really nice if someone could explain why I have to declare it in every specific class I want to use it, not only in a parent class.
          Thanks!

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Because without it, it's just a plain class. QObject based class with signals and slots needs to have moc run on them to generate additional code (the moc files) so Qt can do its magic with signals, slots, introspection etc.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            NiagarerN 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              Because without it, it's just a plain class. QObject based class with signals and slots needs to have moc run on them to generate additional code (the moc files) so Qt can do its magic with signals, slots, introspection etc.

              NiagarerN Offline
              NiagarerN Offline
              Niagarer
              wrote on last edited by
              #6

              @SGaist
              But it's derived from a class that is derived from QObject. Why don't do the child classes overtake the Q_Widget macro from it's parent?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Because they are two different objects. That macro is not empty. It generates the static meta object that is needed for introspection and signal and slots to work among other things and again, it's needed by moc to properly do its work.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                NiagarerN 1 Reply Last reply
                1
                • SGaistS SGaist

                  Because they are two different objects. That macro is not empty. It generates the static meta object that is needed for introspection and signal and slots to work among other things and again, it's needed by moc to properly do its work.

                  NiagarerN Offline
                  NiagarerN Offline
                  Niagarer
                  wrote on last edited by
                  #8

                  @SGaist
                  Ok, thanks.
                  I was wondering, because I thought, that a child class gets also every macro called in the parent class, but it seems to be different. The preprocessor does not seem to add that code in the child classes. Is there a way to do this? I mean, with huge inheritence trees, maybe it's just too uncomfortable to add a needed macro in every class.

                  1 Reply Last reply
                  1
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Macros can't be inherited, they are placeholders that are replaced at compilation time. That said, trying to circumvent that is a bad idea. The Q_OBJECT macro also serves as a hint to the developer that this class is going to use some feature of the Qt Meta Object system e.g. a property, a signal, a slot etc. Also note that you only need that macro in classes where you'll be using one of these features, otherwise not.

                    Removing that macro from everywhere, you would only make your code harder to understand.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    NiagarerN 1 Reply Last reply
                    4
                    • SGaistS SGaist

                      Macros can't be inherited, they are placeholders that are replaced at compilation time. That said, trying to circumvent that is a bad idea. The Q_OBJECT macro also serves as a hint to the developer that this class is going to use some feature of the Qt Meta Object system e.g. a property, a signal, a slot etc. Also note that you only need that macro in classes where you'll be using one of these features, otherwise not.

                      Removing that macro from everywhere, you would only make your code harder to understand.

                      NiagarerN Offline
                      NiagarerN Offline
                      Niagarer
                      wrote on last edited by
                      #10

                      @SGaist
                      Ok, sounds logical

                      1 Reply Last reply
                      1

                      • Login

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