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] What is the signature of a function used as SLOT
Forum Updated to NodeBB v4.3 + New Features

[Solved] What is the signature of a function used as SLOT

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.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.
  • D Offline
    D Offline
    d.oberkofler
    wrote on last edited by
    #1

    I was wondering what signature (type of the parameter theSlot) must be used for function that will be used as a slot:
    I know that connect actually gets the slot as a simple const char* but the following example does not work and the compiler reports theSlot as an unreferenced parameter:
    @
    void addMenuItem(QMenu* theMenu, const QString& theTitle, const char* theSlot)
    {
    QAction* aAction = new QAction(theTitle, this);
    connect(aAction, SIGNAL(triggered()), this, SLOT(theSlot));
    theMenu->addAction(aAction);
    }

    void buildMenu(QMenu* theMenu)
    {
    addMenuItem(theMenu, "Open file...", "slot_open_file()");
    }
    @

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vcsala
      wrote on last edited by
      #2

      You have missunderstood the thing a bit. If you use SLOT (which is a kind of macro understood by the moc compiler) it should be a method name and its parameter types without quotes. However connect's 4th parameter has type const char*, so in your sample the SLOT is not required.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vcsala
        wrote on last edited by
        #3

        You can read more about it "here":http://doc.qt.nokia.com/4.7/signalsandslots.html

        1 Reply Last reply
        0
        • D Offline
          D Offline
          d.oberkofler
          wrote on last edited by
          #4

          I played around a little and actually the const char* parameter type and the use of SLOT was OK but I used slot on the wrong argument.

          The following example does work as expected:
          @
          void addMenuItem(QMenu* theMenu, const QString& theTitle, const char* theSlot)
          {
          QAction* aAction = new QAction(theTitle, this);
          connect(aAction, SIGNAL(triggered()), this, theSlot);
          theMenu->addAction(aAction);
          }

          void buildMenu(QMenu* theMenu)
          {
          addMenuItem(theMenu, "Open file...", SLOT(slot_open_file()));
          }
          @

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            That is the correct usage. Then you don't care how SLOT is done :-)

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            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