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. I do not understand this syntax, which does not work

I do not understand this syntax, which does not work

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.9k Views
  • 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
    nostrora
    wrote on last edited by
    #1

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

      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
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        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
        0

        • Login

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