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. Help with connect statement
QtWS25 Last Chance

Help with connect statement

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 8 Posters 3.6k 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.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #1

    Hi All,

    I'm trying to extend the CAN example (in examples - Qt Creator 4.9.1 / Qt 5.12.3) by adding a class that decodes some CAN messages and then displays the data on my own QML screen.

    I've added a message processor class, with a function under public slots:

    void pIncomingMessage(const QString message);
    

    and a signal in the 'processReceivedFrames() function in 'MainWindow.cpp' :

    void canMessageOut(const QString outGoingMessage);
    

    I haven't been able to get a connect statement to work anywhere (interpreter didn't like any variation of connect statement) until I finally put the statement in main.cpp:

    int main(int argc, char *argv[])
    {
        QLoggingCategory::setFilterRules(QStringLiteral("qt.canbus* = true"));
        QApplication a(argc, argv);    
    
        MainWindow w;
    
        QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor::pIncomingMessage);
    
        w.show();
    
        return a.exec();
    }
    

    and the interpreter doesn't throw an error, but it fails at runtime with LOTS of red ink in the compile screen. I'll put the compile output here, with the hope something makes sense to one of the gurus out there. I'm guessing the important clues have to do with the messages: 'no known conversion for argument 2'... but I have no idea what the problem could be.

    In file included from C:\Qt\5.12.3\mingw73_64\include\QtSerialBus/qcanbusdevice.h:40:0,
    from C:\Qt\5.12.3\mingw73_64\include\QtSerialBus/QCanBusDevice:1,
    from ..\monitorpBus\mainwindow.h:4,
    from ..\monitorpBus\main.cpp:1:
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In instantiation of 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]':
    ..\monitorpBus\main.cpp:16:90: required from here
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: error: no matching function for call to 'QObject::connect(const Object*&, void (MainWindow::&)(QString), const Object&, void (pMessageProcessor::&)(QString), Qt::ConnectionType)'
    return connect(sender, signal, sender, slot, Qt::DirectConnection);
    ^
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:208:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject
    , const char*, const QObject*, const char*, Qt::ConnectionType)
    static QMetaObject::Connection connect(const QObject sender, const char signal,
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:208:36: note: no known conversion for argument 2 from 'void (MainWindow::
    )(QString)' to 'const char
    '
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:211:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
    static QMetaObject::Connection connect(const QObject sender, const QMetaMethod &signal,
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:211:36: note: no known conversion for argument 2 from 'void (MainWindow::
    )(QString)' to 'const QMetaMethod&'
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:463:32: note: candidate: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
    inline QMetaObject::Connection QObject::connect(const QObject asender, const char asignal,
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:463:32: note: candidate expects 4 arguments, 5 provided
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:228:43: note: candidate: static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
    , Func1, const typename QtPrivate::FunctionPointer<Func2>::Object
    , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename QtPrivate::FunctionPointer<Func>::Object = MainWindow; typename QtPrivate::FunctionPointer<Func2>::Object = pMessageProcessor]
    static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal,
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:228:43: note: no known conversion for argument 3 from 'const Object
    {aka const MainWindow*}' to 'const Object* {aka const pMessageProcessor*}'
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:260:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
    connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:260:13: note: template argument deduction/substitution failed:
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: note: candidate expects 3 arguments, 5 provided
    return connect(sender, signal, sender, slot, Qt::DirectConnection);
    ^
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
    , Func1, const QObject*, Func2, Qt::ConnectionType)
    connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, const QObject context, Func2 slot,
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: note: template argument deduction/substitution failed:
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
    , Func1, const QObject
    , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString)]':
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: required from 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]'
    ..\monitorpBus\main.cpp:16:90: required from here
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In instantiation of 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]':
    ..\monitorpBus\main.cpp:16:90: required from here
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:300:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
    connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:300:13: note: template argument deduction/substitution failed:
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: note: candidate expects 3 arguments, 5 provided
    return connect(sender, signal, sender, slot, Qt::DirectConnection);
    ^
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
    , Func1, const QObject*, Func2, Qt::ConnectionType)
    connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, const QObject context, Func2 slot,
    ^~~~~~~
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: note: template argument deduction/substitution failed:
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
    , Func1, const QObject
    , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString)]':
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: required from 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]'
    ..\monitorpBus\main.cpp:16:90: required from here
    C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
    mingw32-make[1]: *** [Makefile.Debug:3009: debug/main.o] Error 1
    mingw32-make[1]: *** Waiting for unfinished jobs....

    JKSHJ jsulmJ 2 Replies Last reply
    0
    • M MScottM

      Hi All,

      I'm trying to extend the CAN example (in examples - Qt Creator 4.9.1 / Qt 5.12.3) by adding a class that decodes some CAN messages and then displays the data on my own QML screen.

      I've added a message processor class, with a function under public slots:

      void pIncomingMessage(const QString message);
      

      and a signal in the 'processReceivedFrames() function in 'MainWindow.cpp' :

      void canMessageOut(const QString outGoingMessage);
      

      I haven't been able to get a connect statement to work anywhere (interpreter didn't like any variation of connect statement) until I finally put the statement in main.cpp:

      int main(int argc, char *argv[])
      {
          QLoggingCategory::setFilterRules(QStringLiteral("qt.canbus* = true"));
          QApplication a(argc, argv);    
      
          MainWindow w;
      
          QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor::pIncomingMessage);
      
          w.show();
      
          return a.exec();
      }
      

      and the interpreter doesn't throw an error, but it fails at runtime with LOTS of red ink in the compile screen. I'll put the compile output here, with the hope something makes sense to one of the gurus out there. I'm guessing the important clues have to do with the messages: 'no known conversion for argument 2'... but I have no idea what the problem could be.

      In file included from C:\Qt\5.12.3\mingw73_64\include\QtSerialBus/qcanbusdevice.h:40:0,
      from C:\Qt\5.12.3\mingw73_64\include\QtSerialBus/QCanBusDevice:1,
      from ..\monitorpBus\mainwindow.h:4,
      from ..\monitorpBus\main.cpp:1:
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In instantiation of 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]':
      ..\monitorpBus\main.cpp:16:90: required from here
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: error: no matching function for call to 'QObject::connect(const Object*&, void (MainWindow::&)(QString), const Object&, void (pMessageProcessor::&)(QString), Qt::ConnectionType)'
      return connect(sender, signal, sender, slot, Qt::DirectConnection);
      ^
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:208:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject
      , const char*, const QObject*, const char*, Qt::ConnectionType)
      static QMetaObject::Connection connect(const QObject sender, const char signal,
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:208:36: note: no known conversion for argument 2 from 'void (MainWindow::
      )(QString)' to 'const char
      '
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:211:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
      static QMetaObject::Connection connect(const QObject sender, const QMetaMethod &signal,
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:211:36: note: no known conversion for argument 2 from 'void (MainWindow::
      )(QString)' to 'const QMetaMethod&'
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:463:32: note: candidate: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
      inline QMetaObject::Connection QObject::connect(const QObject asender, const char asignal,
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:463:32: note: candidate expects 4 arguments, 5 provided
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:228:43: note: candidate: static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
      , Func1, const typename QtPrivate::FunctionPointer<Func2>::Object
      , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename QtPrivate::FunctionPointer<Func>::Object = MainWindow; typename QtPrivate::FunctionPointer<Func2>::Object = pMessageProcessor]
      static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal,
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:228:43: note: no known conversion for argument 3 from 'const Object
      {aka const MainWindow*}' to 'const Object* {aka const pMessageProcessor*}'
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:260:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
      connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:260:13: note: template argument deduction/substitution failed:
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: note: candidate expects 3 arguments, 5 provided
      return connect(sender, signal, sender, slot, Qt::DirectConnection);
      ^
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
      , Func1, const QObject*, Func2, Qt::ConnectionType)
      connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, const QObject context, Func2 slot,
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: note: template argument deduction/substitution failed:
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
      , Func1, const QObject
      , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString)]':
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: required from 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]'
      ..\monitorpBus\main.cpp:16:90: required from here
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In instantiation of 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]':
      ..\monitorpBus\main.cpp:16:90: required from here
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:300:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
      connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:300:13: note: template argument deduction/substitution failed:
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: note: candidate expects 3 arguments, 5 provided
      return connect(sender, signal, sender, slot, Qt::DirectConnection);
      ^
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
      , Func1, const QObject*, Func2, Qt::ConnectionType)
      connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, const QObject context, Func2 slot,
      ^~~~~~~
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: note: template argument deduction/substitution failed:
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
      , Func1, const QObject
      , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString)]':
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: required from 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]'
      ..\monitorpBus\main.cpp:16:90: required from here
      C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
      mingw32-make[1]: *** [Makefile.Debug:3009: debug/main.o] Error 1
      mingw32-make[1]: *** Waiting for unfinished jobs....

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @mscottm said in Help with connect statement:

      QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor::pIncomingMessage);
      

      You're missing the 3rd argument: A pointer to the receiver instance

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

      1 Reply Last reply
      8
      • M MScottM

        Hi All,

        I'm trying to extend the CAN example (in examples - Qt Creator 4.9.1 / Qt 5.12.3) by adding a class that decodes some CAN messages and then displays the data on my own QML screen.

        I've added a message processor class, with a function under public slots:

        void pIncomingMessage(const QString message);
        

        and a signal in the 'processReceivedFrames() function in 'MainWindow.cpp' :

        void canMessageOut(const QString outGoingMessage);
        

        I haven't been able to get a connect statement to work anywhere (interpreter didn't like any variation of connect statement) until I finally put the statement in main.cpp:

        int main(int argc, char *argv[])
        {
            QLoggingCategory::setFilterRules(QStringLiteral("qt.canbus* = true"));
            QApplication a(argc, argv);    
        
            MainWindow w;
        
            QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor::pIncomingMessage);
        
            w.show();
        
            return a.exec();
        }
        

        and the interpreter doesn't throw an error, but it fails at runtime with LOTS of red ink in the compile screen. I'll put the compile output here, with the hope something makes sense to one of the gurus out there. I'm guessing the important clues have to do with the messages: 'no known conversion for argument 2'... but I have no idea what the problem could be.

        In file included from C:\Qt\5.12.3\mingw73_64\include\QtSerialBus/qcanbusdevice.h:40:0,
        from C:\Qt\5.12.3\mingw73_64\include\QtSerialBus/QCanBusDevice:1,
        from ..\monitorpBus\mainwindow.h:4,
        from ..\monitorpBus\main.cpp:1:
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In instantiation of 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]':
        ..\monitorpBus\main.cpp:16:90: required from here
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: error: no matching function for call to 'QObject::connect(const Object*&, void (MainWindow::&)(QString), const Object&, void (pMessageProcessor::&)(QString), Qt::ConnectionType)'
        return connect(sender, signal, sender, slot, Qt::DirectConnection);
        ^
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:208:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject
        , const char*, const QObject*, const char*, Qt::ConnectionType)
        static QMetaObject::Connection connect(const QObject sender, const char signal,
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:208:36: note: no known conversion for argument 2 from 'void (MainWindow::
        )(QString)' to 'const char
        '
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:211:36: note: candidate: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
        static QMetaObject::Connection connect(const QObject sender, const QMetaMethod &signal,
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:211:36: note: no known conversion for argument 2 from 'void (MainWindow::
        )(QString)' to 'const QMetaMethod&'
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:463:32: note: candidate: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
        inline QMetaObject::Connection QObject::connect(const QObject asender, const char asignal,
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:463:32: note: candidate expects 4 arguments, 5 provided
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:228:43: note: candidate: static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
        , Func1, const typename QtPrivate::FunctionPointer<Func2>::Object
        , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename QtPrivate::FunctionPointer<Func>::Object = MainWindow; typename QtPrivate::FunctionPointer<Func2>::Object = pMessageProcessor]
        static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal,
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:228:43: note: no known conversion for argument 3 from 'const Object
        {aka const MainWindow*}' to 'const Object* {aka const pMessageProcessor*}'
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:260:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
        connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:260:13: note: template argument deduction/substitution failed:
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: note: candidate expects 3 arguments, 5 provided
        return connect(sender, signal, sender, slot, Qt::DirectConnection);
        ^
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
        , Func1, const QObject*, Func2, Qt::ConnectionType)
        connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, const QObject context, Func2 slot,
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: note: template argument deduction/substitution failed:
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
        , Func1, const QObject
        , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString)]':
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: required from 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]'
        ..\monitorpBus\main.cpp:16:90: required from here
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:269:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In instantiation of 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]':
        ..\monitorpBus\main.cpp:16:90: required from here
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:300:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
        connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:300:13: note: template argument deduction/substitution failed:
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: note: candidate expects 3 arguments, 5 provided
        return connect(sender, signal, sender, slot, Qt::DirectConnection);
        ^
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: note: candidate: template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
        , Func1, const QObject*, Func2, Qt::ConnectionType)
        connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, const QObject context, Func2 slot,
        ^~~~~~~
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: note: template argument deduction/substitution failed:
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object
        , Func1, const QObject
        , Func2, Qt::ConnectionType) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString)]':
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:262:74: required from 'static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2) [with Func1 = void (MainWindow::)(QString); Func2 = void (pMessageProcessor::)(QString); typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type = QMetaObject::Connection; typename QtPrivate::FunctionPointer<Func>::Object = MainWindow]'
        ..\monitorpBus\main.cpp:16:90: required from here
        C:\Qt\5.12.3\mingw73_64\include/QtCore/qobject.h:308:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
        mingw32-make[1]: *** [Makefile.Debug:3009: debug/main.o] Error 1
        mingw32-make[1]: *** Waiting for unfinished jobs....

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @mscottm said in Help with connect statement:

        QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor::pIncomingMessage);

        This can't work: you need an instance of pMessageProcessor class (I don't see any in your code).
        Like:

        int main(int argc, char *argv[])
        {
            QLoggingCategory::setFilterRules(QStringLiteral("qt.canbus* = true"));
            QApplication a(argc, argv);    
        
            MainWindow w;
            pMessageProcessor proc;
        
            QObject::connect(&w, &MainWindow::canMessageOut, &proc, &pMessageProcessor::pIncomingMessage);
        
            w.show();
        
            return a.exec();
        }
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        5
        • M Offline
          M Offline
          MScottM
          wrote on last edited by
          #4

          When I add in the instance to the statement like so:

          QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
          

          the interpreter underlines it (&pMessageProcessor) and says "pMessageProcessor does not refer to a value"...then..."declared here" and points to the pMessageProcessor.h file line number where the class is declared:

          class pMessageProcessor : public QObject
          
          J.HilkJ Pl45m4P 2 Replies Last reply
          0
          • M MScottM

            When I add in the instance to the statement like so:

            QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
            

            the interpreter underlines it (&pMessageProcessor) and says "pMessageProcessor does not refer to a value"...then..."declared here" and points to the pMessageProcessor.h file line number where the class is declared:

            class pMessageProcessor : public QObject
            
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @mscottm

            do not forget the
            Q_OBJECT
            inside your class


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MScottM
              wrote on last edited by MScottM
              #6

              Sorry, here is the whole class .h file - it is there:

              #ifndef PMESSAGEPROCESSOR_H
              #define PMESSAGEPROCESSOR_H
              
              #include <QHash>
              #include <QObject>
              #include <QDebug>
              
              class pMessageProcessor : public QObject
              {
                  Q_OBJECT    
              
              public:
                  qint16 pValue;
              
                  pMessageProcessor();
              
                  void analogInputs(QString, QString);
              
                  void analogInputsMessage(QString, qint16, qint16, qint16, qint16);
              
              public slots:
                  void pIncomingMessage(QString message);
              
              signals:
                  void analogInputsValue( QString pgn, QString sourceAddress, qint16 analogInputOne,
                                          qint16 analogInputTwo, qint16 analogInputThree, qint16 analogInputFour);
              
              private:
                  bool ok;
                  int pgnTest;
                  QString message1;
                  QString message2;
                  QStringList parts;
                  QString leftPart;
                  QString pgn;
                  QString data;
                  QString srcAddress;
              
                  QHash<QString, int> pHash;
              
              };
              
              #endif // PMESSAGEPROCESSOR_H
              
              1 Reply Last reply
              0
              • M MScottM

                When I add in the instance to the statement like so:

                QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                

                the interpreter underlines it (&pMessageProcessor) and says "pMessageProcessor does not refer to a value"...then..."declared here" and points to the pMessageProcessor.h file line number where the class is declared:

                class pMessageProcessor : public QObject
                
                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by Pl45m4
                #7

                @mscottm said in Help with connect statement:

                QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);

                In addition to @J-Hilk :

                If pMessageProcessor is already a pointer to your class instance, then you have to remove the &.

                MainWindow w is referenced by using &w in your connect-statement because it is NOT a pointer.

                Try:

                pMessageProcessor * pMProc = new pMessageProcessor();
                // [ ... ]
                QObject::connect(&w, &MainWindow::canMessageOut, pMProc, &pMessageProcessor::pIncomingMessage);
                

                Sender param != class of sender (you need the actual instance of that class there)


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                Pradeep P NP 1 Reply Last reply
                4
                • Pl45m4P Pl45m4

                  @mscottm said in Help with connect statement:

                  QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);

                  In addition to @J-Hilk :

                  If pMessageProcessor is already a pointer to your class instance, then you have to remove the &.

                  MainWindow w is referenced by using &w in your connect-statement because it is NOT a pointer.

                  Try:

                  pMessageProcessor * pMProc = new pMessageProcessor();
                  // [ ... ]
                  QObject::connect(&w, &MainWindow::canMessageOut, pMProc, &pMessageProcessor::pIncomingMessage);
                  

                  Sender param != class of sender (you need the actual instance of that class there)

                  Pradeep P NP Offline
                  Pradeep P NP Offline
                  Pradeep P N
                  wrote on last edited by Pradeep P N
                  #8

                  @pl45m4
                  I think it should be
                  connect(&w, &MainWindow::canMessageOut, mp, &pMessageProcessor::pIncomingMessage);
                  right ?
                  from this line pMessageProcessor * mp = new pMessageProcessor();

                  Please tell if i am missing something.

                  Pradeep Nimbalkar.
                  Upvote the answer(s) that helped you to solve the issue...
                  Keep code clean.

                  Pl45m4P 1 Reply Last reply
                  3
                  • Pradeep P NP Pradeep P N

                    @pl45m4
                    I think it should be
                    connect(&w, &MainWindow::canMessageOut, mp, &pMessageProcessor::pIncomingMessage);
                    right ?
                    from this line pMessageProcessor * mp = new pMessageProcessor();

                    Please tell if i am missing something.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #9

                    @pradeep-p-n

                    After re-reading my "code" I realized that I messed it up :)
                    (Realized too late that pMessageProcessor is not the instance, but the class name -> low case first letter?!)
                    I've edited my answer....

                    I hope OP gets the point


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    Pradeep P NP 1 Reply Last reply
                    0
                    • Pl45m4P Pl45m4

                      @pradeep-p-n

                      After re-reading my "code" I realized that I messed it up :)
                      (Realized too late that pMessageProcessor is not the instance, but the class name -> low case first letter?!)
                      I've edited my answer....

                      I hope OP gets the point

                      Pradeep P NP Offline
                      Pradeep P NP Offline
                      Pradeep P N
                      wrote on last edited by Pradeep P N
                      #10

                      @pl45m4
                      Cool,

                      All the best.

                      Pradeep Nimbalkar.
                      Upvote the answer(s) that helped you to solve the issue...
                      Keep code clean.

                      1 Reply Last reply
                      2
                      • M Offline
                        M Offline
                        MScottM
                        wrote on last edited by
                        #11

                        Error remains the same: "pMessageProcessor does not refer to a value".

                        I will also say that when I move the connect statement into 'MainWindow.cpp', like so:

                        QObject::connect(this, processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                        

                        the error is the same ..."pMessageProcessor does not refer to a value". And when I move the statement into the pMessageProcessor.cpp file like so:

                        connect(&MainWindow, &MainWindow::processReceivedFrames, &pMessageProcessor, pMessageProcessor::pIncomingMessage());
                        

                        the interpreter has three errors: "MainWindow does not refer to a value", "pMessageProcessor does not refer to a value", "cpp:11: error: too few arguments to function call, single argument 'message' was not specified"

                        Pl45m4P 1 Reply Last reply
                        0
                        • M MScottM

                          Error remains the same: "pMessageProcessor does not refer to a value".

                          I will also say that when I move the connect statement into 'MainWindow.cpp', like so:

                          QObject::connect(this, processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                          

                          the error is the same ..."pMessageProcessor does not refer to a value". And when I move the statement into the pMessageProcessor.cpp file like so:

                          connect(&MainWindow, &MainWindow::processReceivedFrames, &pMessageProcessor, pMessageProcessor::pIncomingMessage());
                          

                          the interpreter has three errors: "MainWindow does not refer to a value", "pMessageProcessor does not refer to a value", "cpp:11: error: too few arguments to function call, single argument 'message' was not specified"

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by Pl45m4
                          #12

                          @mscottm

                          Take a look at my (edited) answer.

                          Again:

                          // a and b = no pointer
                          Sender a;
                          Receiver b;
                          // Take address from a and b with &
                          connect(&a, &Sender::signal, &b, &Receiver::slot);
                          

                          or

                          //  a and b = pointers
                          Sender * a = new Sender();
                          Receiver * b = new Receiver();
                          // NO & in connection
                          connect(a, &Sender::signal, b, &Receiver::slot);
                          

                          If you mix a pointer with &, your connection cannot work :)

                          Here's another example :)
                          https://doc.qt.io/qt-5/signalsandslots.html#a-small-example


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          Pradeep P NP 1 Reply Last reply
                          4
                          • Pl45m4P Pl45m4

                            @mscottm

                            Take a look at my (edited) answer.

                            Again:

                            // a and b = no pointer
                            Sender a;
                            Receiver b;
                            // Take address from a and b with &
                            connect(&a, &Sender::signal, &b, &Receiver::slot);
                            

                            or

                            //  a and b = pointers
                            Sender * a = new Sender();
                            Receiver * b = new Receiver();
                            // NO & in connection
                            connect(a, &Sender::signal, b, &Receiver::slot);
                            

                            If you mix a pointer with &, your connection cannot work :)

                            Here's another example :)
                            https://doc.qt.io/qt-5/signalsandslots.html#a-small-example

                            Pradeep P NP Offline
                            Pradeep P NP Offline
                            Pradeep P N
                            wrote on last edited by Pradeep P N
                            #13

                            @pl45m4 said in Help with connect statement:

                            If you mix a pointer with &, your connection cannot work :)

                            Are you sure of this ?

                            I did try a sample, it works.
                            QObject::connect(&w, &Widget::sendMsg, mtc, &MyTestClass::receiveMsg);

                            • main.cpp
                            int main(int argc, char *argv[])
                            {
                                QApplication a(argc, argv);
                            
                                Widget w;
                                MyTestClass *mtc = new MyTestClass;
                            
                                QObject::connect(&w, &Widget::sendMsg, mtc, &MyTestClass::receiveMsg);
                            
                                return a.exec();
                            }
                            
                            • Widget Class
                            // .h File
                            signals:
                                void sendMsg(const QString msg);
                            
                            // .cpp File
                            Widget::Widget(QWidget *parent)
                                : QWidget(parent)
                                , m_Count(0)
                                , m_testTimer(new QTimer(this))
                            {
                                m_testTimer->start();
                                m_testTimer->setInterval(3000);
                            
                                connect(m_testTimer, &QTimer::timeout, [this]{
                                    m_Count++;
                                    emit sendMsg(" Number Sent :: " + QString::number(m_Count));
                                });
                            }
                            
                            • MyTestClass
                            // .h File
                            public slots:
                                void receiveMsg(const QString msg);
                            
                            //.cpp File
                            void MyTestClass::receiveMsg(const QString msg)
                            {
                                qDebug() << Q_FUNC_INFO << msg;
                            }
                            
                            

                            Output:

                            void MyTestClass::receiveMsg(QString) " Number Sent :: 1"
                            void MyTestClass::receiveMsg(QString) " Number Sent :: 2"
                            void MyTestClass::receiveMsg(QString) " Number Sent :: 3"
                            void MyTestClass::receiveMsg(QString) " Number Sent :: 4"
                            void MyTestClass::receiveMsg(QString) " Number Sent :: 5"
                            void MyTestClass::receiveMsg(QString) " Number Sent :: 6"
                            

                            Pradeep Nimbalkar.
                            Upvote the answer(s) that helped you to solve the issue...
                            Keep code clean.

                            SGaistS 1 Reply Last reply
                            0
                            • Pradeep P NP Pradeep P N

                              @pl45m4 said in Help with connect statement:

                              If you mix a pointer with &, your connection cannot work :)

                              Are you sure of this ?

                              I did try a sample, it works.
                              QObject::connect(&w, &Widget::sendMsg, mtc, &MyTestClass::receiveMsg);

                              • main.cpp
                              int main(int argc, char *argv[])
                              {
                                  QApplication a(argc, argv);
                              
                                  Widget w;
                                  MyTestClass *mtc = new MyTestClass;
                              
                                  QObject::connect(&w, &Widget::sendMsg, mtc, &MyTestClass::receiveMsg);
                              
                                  return a.exec();
                              }
                              
                              • Widget Class
                              // .h File
                              signals:
                                  void sendMsg(const QString msg);
                              
                              // .cpp File
                              Widget::Widget(QWidget *parent)
                                  : QWidget(parent)
                                  , m_Count(0)
                                  , m_testTimer(new QTimer(this))
                              {
                                  m_testTimer->start();
                                  m_testTimer->setInterval(3000);
                              
                                  connect(m_testTimer, &QTimer::timeout, [this]{
                                      m_Count++;
                                      emit sendMsg(" Number Sent :: " + QString::number(m_Count));
                                  });
                              }
                              
                              • MyTestClass
                              // .h File
                              public slots:
                                  void receiveMsg(const QString msg);
                              
                              //.cpp File
                              void MyTestClass::receiveMsg(const QString msg)
                              {
                                  qDebug() << Q_FUNC_INFO << msg;
                              }
                              
                              

                              Output:

                              void MyTestClass::receiveMsg(QString) " Number Sent :: 1"
                              void MyTestClass::receiveMsg(QString) " Number Sent :: 2"
                              void MyTestClass::receiveMsg(QString) " Number Sent :: 3"
                              void MyTestClass::receiveMsg(QString) " Number Sent :: 4"
                              void MyTestClass::receiveMsg(QString) " Number Sent :: 5"
                              void MyTestClass::receiveMsg(QString) " Number Sent :: 6"
                              
                              SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @pradeep-p-n what @Pl45m4 was warning against is using & when the target is already a pointer to an object.

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

                              Pradeep P NP 1 Reply Last reply
                              2
                              • SGaistS SGaist

                                @pradeep-p-n what @Pl45m4 was warning against is using & when the target is already a pointer to an object.

                                Pradeep P NP Offline
                                Pradeep P NP Offline
                                Pradeep P N
                                wrote on last edited by
                                #15

                                Ah, how did i misunderstood that.
                                Oops @Pl45m4 i got it.
                                @SGaist Thanks.

                                Pradeep Nimbalkar.
                                Upvote the answer(s) that helped you to solve the issue...
                                Keep code clean.

                                1 Reply Last reply
                                2
                                • M Offline
                                  M Offline
                                  MScottM
                                  wrote on last edited by MScottM
                                  #16

                                  I've tried many variations of the above thoughts - no version of the connect statement works. Here's a little of what I've tried (these are not the only variations).

                                  When in main.cpp:

                                  QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter: error: 'pMessageProcessor' does not refer to a value

                                  QObject::connect(w, &MainWindow::canMessageOut, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter: error: 'pMessageProcessor' does not refer to a value

                                  QObject::connect(w, MainWindow::canMessageOut, pMessageProcessor, pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter:
                                  error: call to non-static member function without an object argument,
                                  error: 'pMessageProcessor' does not refer to a value,
                                  error: call to non-static member function without an object argument

                                  Connect statement in MainWindow.cpp:

                                  QObject::connect(this, processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter: error: 'pMessageProcessor' does not refer to a value

                                  QObject::connect(this, processReceivedFrames, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter: error: 'pMessageProcessor' does not refer to a value

                                  QObject::connect(this, processReceivedFrames, pMessageProcessor, pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter:
                                  error: 'pMessageProcessor' does not refer to a value
                                  error: call to non-static member function without an object argument

                                  and so on...

                                  connect statement in pMessageProcessor.cpp:

                                  connect(&MainWindow, &MainWindow::processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter:
                                  error: 'MainWindow' does not refer to a value
                                  error: 'pMessageProcessor' does not refer to a value

                                  connect(MainWindow, &MainWindow::processReceivedFrames, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                  

                                  interpreter:
                                  error: 'MainWindow' does not refer to a value
                                  error: 'pMessageProcessor' does not refer to a value

                                  and so on...

                                  I don't think that the connect statement is the issue, but I'm too much of a beginner to know what else to look for in the code.

                                  I appreciate the help so far!

                                  Oh - and if it's not clear - I'm trying the connect statement in one place only - not in three places.

                                  aha_1980A Pl45m4P 2 Replies Last reply
                                  0
                                  • M MScottM

                                    I've tried many variations of the above thoughts - no version of the connect statement works. Here's a little of what I've tried (these are not the only variations).

                                    When in main.cpp:

                                    QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter: error: 'pMessageProcessor' does not refer to a value

                                    QObject::connect(w, &MainWindow::canMessageOut, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter: error: 'pMessageProcessor' does not refer to a value

                                    QObject::connect(w, MainWindow::canMessageOut, pMessageProcessor, pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter:
                                    error: call to non-static member function without an object argument,
                                    error: 'pMessageProcessor' does not refer to a value,
                                    error: call to non-static member function without an object argument

                                    Connect statement in MainWindow.cpp:

                                    QObject::connect(this, processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter: error: 'pMessageProcessor' does not refer to a value

                                    QObject::connect(this, processReceivedFrames, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter: error: 'pMessageProcessor' does not refer to a value

                                    QObject::connect(this, processReceivedFrames, pMessageProcessor, pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter:
                                    error: 'pMessageProcessor' does not refer to a value
                                    error: call to non-static member function without an object argument

                                    and so on...

                                    connect statement in pMessageProcessor.cpp:

                                    connect(&MainWindow, &MainWindow::processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter:
                                    error: 'MainWindow' does not refer to a value
                                    error: 'pMessageProcessor' does not refer to a value

                                    connect(MainWindow, &MainWindow::processReceivedFrames, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                    

                                    interpreter:
                                    error: 'MainWindow' does not refer to a value
                                    error: 'pMessageProcessor' does not refer to a value

                                    and so on...

                                    I don't think that the connect statement is the issue, but I'm too much of a beginner to know what else to look for in the code.

                                    I appreciate the help so far!

                                    Oh - and if it's not clear - I'm trying the connect statement in one place only - not in three places.

                                    aha_1980A Offline
                                    aha_1980A Offline
                                    aha_1980
                                    Lifetime Qt Champion
                                    wrote on last edited by aha_1980
                                    #17

                                    Hi @mscottm,

                                    it seems you have a fundamental understanding problem, and that in turn will make it hard for others to understand your problem, because the description is already wrong.

                                    and the interpreter doesn't throw an error, but it fails at runtime with LOTS of red ink in the compile screen.

                                    You probably mean: the code model does not show errors, but the program does not compile and the compile output shows LOTS of errors.

                                    Runtime, however, comes after your program successfully compiled and linked - when your program is actually running.

                                    Regarding your real problem: Why don't you just show your code? We can guess for long here, or simply have a look at it. It can either take long or you can get an answer very quick - it just depends on you.

                                    connect(&MainWindow, &MainWindow::processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);

                                    You need to understand that the first and third parameter of connect need to be a pointer to a variable, while the second and the fourth need to be a pointer to a member function (the second: a signal, the fourth: a slot).

                                    In your example the parameters one and three are a class, not a variable, therefore it will not compile.

                                    Example how it could look like:

                                    MainWindow window;
                                    pMessageProcessor processor;
                                    connect(&window, &MainWindow::processReceivedFrames, 
                                    &processor, &pMessageProcessor::pIncomingMessage);
                                    

                                    As you can see, for the connect you need to have both classes as variable, and then it will work.

                                    Regards

                                    Qt has to stay free or it will die.

                                    1 Reply Last reply
                                    2
                                    • M MScottM

                                      I've tried many variations of the above thoughts - no version of the connect statement works. Here's a little of what I've tried (these are not the only variations).

                                      When in main.cpp:

                                      QObject::connect(&w, &MainWindow::canMessageOut, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter: error: 'pMessageProcessor' does not refer to a value

                                      QObject::connect(w, &MainWindow::canMessageOut, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter: error: 'pMessageProcessor' does not refer to a value

                                      QObject::connect(w, MainWindow::canMessageOut, pMessageProcessor, pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter:
                                      error: call to non-static member function without an object argument,
                                      error: 'pMessageProcessor' does not refer to a value,
                                      error: call to non-static member function without an object argument

                                      Connect statement in MainWindow.cpp:

                                      QObject::connect(this, processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter: error: 'pMessageProcessor' does not refer to a value

                                      QObject::connect(this, processReceivedFrames, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter: error: 'pMessageProcessor' does not refer to a value

                                      QObject::connect(this, processReceivedFrames, pMessageProcessor, pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter:
                                      error: 'pMessageProcessor' does not refer to a value
                                      error: call to non-static member function without an object argument

                                      and so on...

                                      connect statement in pMessageProcessor.cpp:

                                      connect(&MainWindow, &MainWindow::processReceivedFrames, &pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter:
                                      error: 'MainWindow' does not refer to a value
                                      error: 'pMessageProcessor' does not refer to a value

                                      connect(MainWindow, &MainWindow::processReceivedFrames, pMessageProcessor, &pMessageProcessor::pIncomingMessage);
                                      

                                      interpreter:
                                      error: 'MainWindow' does not refer to a value
                                      error: 'pMessageProcessor' does not refer to a value

                                      and so on...

                                      I don't think that the connect statement is the issue, but I'm too much of a beginner to know what else to look for in the code.

                                      I appreciate the help so far!

                                      Oh - and if it's not clear - I'm trying the connect statement in one place only - not in three places.

                                      Pl45m4P Offline
                                      Pl45m4P Offline
                                      Pl45m4
                                      wrote on last edited by Pl45m4
                                      #18

                                      @mscottm

                                      Your last reply gives the impression that you didn't read our answers to your problem.
                                      In this thread are at least 2-3 helpful explanations (with given code examples) how the connection statement works and how you can connect your signal with your function in your class.

                                      pMessageProcessor is the name of your class and is NOT a valid first or third parameter in your connect statement, neither as pMessageProcessor nor as &pMessageProcessor.
                                      You need the object / instance of this class there.

                                      If your code is compilable and you use your pMessageProcessor class, then there must be an object of this class.

                                      The same for MainWindow (as first / third parameter).


                                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                      ~E. W. Dijkstra

                                      1 Reply Last reply
                                      2
                                      • M Offline
                                        M Offline
                                        MScottM
                                        wrote on last edited by
                                        #19

                                        @JKSH @jsulm @J-Hilk @Pl45m4 @Pradeep-P-N @SGaist @aha_1980

                                        My sincere apologies. This is what I get for trying to solve coding problems when in a hurry, and just skimming the very helpful replies. I was able to solve the connect statement issue based on help given in one of the very first posts by @jsulm - no instance of the class, and @aha_1980 and @Pl45m4, you of course nailed the other issue.

                                        Thank you all for your replies and taking the time to help!

                                        Best regards

                                        1 Reply Last reply
                                        5

                                        • Login

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