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. [SOLVED] function not found?
Qt 6.11 is out! See what's new in the release blog

[SOLVED] function not found?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 2.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.
  • N Offline
    N Offline
    nicky j
    wrote on last edited by
    #1

    Hey all,

    I am trying to have my class emit a custom signal when clicked, but whenever I call connect() it doesn't work. The console tells me "No such slot NBhistoryAction::emitHistoryRequest() in ../NovaBrowser_v8/nbhistory.cpp:7". How is this possible? emitHistoryRequest is in the code.

    Here is all the code:
    @
    class NBhistoryAction : public QAction
    {
    Q_OBJECT
    public:
    explicit NBhistoryAction(QWidget *parent = 0);
    void setHistoryItem(QString item);
    void emitHistoryRequest();

    private:
    QString historyItem;

    signals:
    QString historyRequest(QString Request);
    };
    @

    @
    NBhistoryAction::NBhistoryAction(QWidget *parent)
    : QAction(parent)
    {
    connect(this, SIGNAL(triggered()), SLOT(emitHistoryRequest()));
    }

    void NBhistoryAction::setHistoryItem(QString item)
    {
    historyItem = item;
    }

    void NBhistoryAction::emitHistoryRequest()
    {
    qDebug() << "wow it worked!";
    QString request = this->historyItem;
    emit historyRequest(request);
    }
    @

    Thanks!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      NBhistoryAction::emitHistoryRequest() is not declared as a slot therefore there is no slot called emitHistoryRequest() to connect to.

      @
      class NBhistoryAction : public QAction
      {
      Q_OBJECT
      public:
      explicit NBhistoryAction(QWidget *parent = 0);
      void setHistoryItem(QString item);

      private slots: // or public if that makes sense
      void emitHistoryRequest();

      private:
      QString historyItem;

      signals:
      QString historyRequest(QString Request);
      };
      @

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        Typo? emitHistoryRequest() isn't labeled as a slot in the class definition.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          It's in the code, but it's not a slot.

          You need to put it under "public slots:", not "public:".

          (In fact, it should probably be private, not public)

          EDIT: Oops, too slow ;)

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nicky j
            wrote on last edited by
            #5

            Thank you both, that fixed it!

            Now for a Qt/c++ theory question:
            whats the difference between 'public' and 'public slots'? why can setHistoryItem() be in the 'public' area while emitHistoryRequest() has to be in the 'public slots' area?

            1 Reply Last reply
            0
            • jeremy_kJ Offline
              jeremy_kJ Offline
              jeremy_k
              wrote on last edited by
              #6

              "moc":http://qt-project.org/doc/qt-5/moc.html uses the slots annotation to detect that a function should be added to the meta-object, which is in turn used to handle signal to slot connections, and signal delivery.

              In the code snippet presented, setHistoryItem() isn't used, making it difficult to tell if it will be accessible when desired.

              Asking a question about code? http://eel.is/iso-c++/testcase/

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                [quote author="nicky j" date="1403252619"]whats the difference between 'public' and 'public slots'? why can setHistoryItem() be in the 'public' area while emitHistoryRequest() has to be in the 'public slots' area?[/quote]connect(this, SIGNAL (triggered()), SLOT (emitHistoryRequest()) );

                Only "public/protected/private slots" can be put inside the SLOT () macro

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  A side note: with the c++11 syntax of connect, that doesn't use SIGNAL and SLOT macros you can connect to any non-slot member as well:
                  @
                  connect(this, &NBhistoryAction::triggered, this, &NBhistoryAction::emitHistoryRequest);
                  @

                  1 Reply Last reply
                  0
                  • jeremy_kJ Offline
                    jeremy_kJ Offline
                    jeremy_k
                    wrote on last edited by
                    #9

                    That pointer to member function syntax, although widely referred to as the c++11 syntax, "doesn't require c++11.":http://woboq.com/blog/new-signals-slots-syntax-in-qt5.html

                    Asking a question about code? http://eel.is/iso-c++/testcase/

                    1 Reply Last reply
                    0
                    • Chris KawaC Offline
                      Chris KawaC Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Well yeah, that's true. I call it that because I use it extensively with lambdas, which are c++11. But you're 100% right.

                      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