Qt Forum

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

    Call for Presentations - Qt World Summit

    I do not understand this syntax, which does not work

    General and Desktop
    3
    3
    1756
    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.
    • N
      nostrora last edited by

      Hello,
      in the doc here is the syntax

      @connect (sender, & Sender :: valueChanged,
                    receiver, Receiver & updateValue ::);@

      But it does not work ..
      for example if I wrote this:

      @QObject :: connect (m_actionQuitter, and QAction :: triggered, creerMenu ());@

      is not it?
      it does not work :/

      @FenPrincipale.cpp:72: erreur : C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char ,Qt::ConnectionType) const' : cannot convert parameter 2 from 'void (__thiscall QAction:: )(bool)' to 'const char *'
      There is no context in which this conversion is possible@

      1 Reply Last reply Reply Quote 0
      • J
        Jake007 last edited by

        Try this:
        @QObject::connect(m_actionQuitter, &QAction::triggered, m_Receiver, &ReceiverObject::creerMenu);@

        Replace m_Receiver with class that should receive the signals and ReceiverObject with class type that m_Receiver is.

        Also make sure that parameters are the same in both methods.


        Code is poetry

        1 Reply Last reply Reply Quote 0
        • JKSH
          JKSH Moderators last edited by

          Hello,

          Have a look at C++ syntax for function pointers (especially pointers-to-member-functions).

          For the new version of QObject::connect() with 4 arguments, the arguments are:

          Pointer to the object that emits the signal

          Pointer to the member-function that acts as the signal

          Pointer to the object that receives the signal

          Pointer to the member-function that acts as the slot

          Your example uses a version with 3 arguments, which are:

          Pointer to the object that emits the signal

          Pointer to the member-function that acts as the signal

          Pointer to the non-member-function to be invoked

          [quote author="nostrora" date="1356603974"]in the doc here is the syntax

          @connect (sender, & Sender :: valueChanged,
                        receiver, Receiver & updateValue ::);@
          [/quote]Be careful -- You have an extra "::" at the end

          [quote author="nostrora" date="1356603974"]
          @QObject :: connect (m_actionQuitter, and QAction :: triggered, creerMenu ());@
          [/quote]Don't write "and". In C++, "&" has special meanings.

          If creerMenu() doesn't belong to a class, there are two correct ways to write it:
          @
          QObject::connect(m_actionQuitter, &QAction::triggered, creerMenu);

          QObject::connect(m_actionQuitter, &QAction::triggered, &creerMenu);
          @

          But, if creerMenu() belongs to a class, use Jake007's version.

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

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