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. No matching function for call to QObject::connect
Forum Update on Monday, May 27th 2025

No matching function for call to QObject::connect

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 6 Posters 4.0k 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.
  • D Offline
    D Offline
    Donald Duck
    wrote on last edited by
    #1

    I'm trying to compile this code inside a constructor of a class named MyClass:

    QTimer *timer = new QTimer;
    timer->setInterval(0);
    QObject::connect(timer, &QTimer::timeout, [this](){
        //Do some stuff
    });
    timer->start();
    

    This compiles just fine in Visual Studio on Windows. But with GCC on Linux it gives the error "no matching function for call to 'MyClass::connect(QTimer*&, void(QTimer::*)(QTimer::QPrivateSignal), MyClass::MyClass()::<lambda()>)'. What should I do?

    E YashpalY 2 Replies Last reply
    0
    • D Offline
      D Offline
      Donald Duck
      wrote on last edited by
      #6

      I found the problem. I had to activate C++11, which is not activated be default. In Qt Creator, I had to add the following line:

      CONFIG += c++11
      
      JohanSoloJ 1 Reply Last reply
      1
      • D Donald Duck

        I'm trying to compile this code inside a constructor of a class named MyClass:

        QTimer *timer = new QTimer;
        timer->setInterval(0);
        QObject::connect(timer, &QTimer::timeout, [this](){
            //Do some stuff
        });
        timer->start();
        

        This compiles just fine in Visual Studio on Windows. But with GCC on Linux it gives the error "no matching function for call to 'MyClass::connect(QTimer*&, void(QTimer::*)(QTimer::QPrivateSignal), MyClass::MyClass()::<lambda()>)'. What should I do?

        E Offline
        E Offline
        Eeli K
        wrote on last edited by Eeli K
        #2

        @Donald-Duck It's probably because QTimer::timeout is a private signal, the new style syntax can't access it. If that's the case you have to use the old SIGNAL/SLOT syntax without lambda.

        1 Reply Last reply
        1
        • beeckscheB Offline
          beeckscheB Offline
          beecksche
          wrote on last edited by beecksche
          #3

          @Donald-Duck
          Regarding to the 0-timer I don't know why you need to have a 0-timer in a constructor, but in the doc of QTimer it says to 0-timers http://doc.qt.io/qt-5/qtimer.html#details:

          This is the traditional way of implementing heavy work in GUI applications, but as multithreading is nowadays becoming available on more and more platforms, we expect that zero-millisecond QTimer objects will gradually be replaced by QThreads.

          Otherwise you can use the startTimer() function of the QObject class

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #4

            Hi,

            Which version of Qt are you using in each OS ?

            Also, aren't you missing #include <QTimer> in your .cpp file ?

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

            1 Reply Last reply
            0
            • D Donald Duck

              I'm trying to compile this code inside a constructor of a class named MyClass:

              QTimer *timer = new QTimer;
              timer->setInterval(0);
              QObject::connect(timer, &QTimer::timeout, [this](){
                  //Do some stuff
              });
              timer->start();
              

              This compiles just fine in Visual Studio on Windows. But with GCC on Linux it gives the error "no matching function for call to 'MyClass::connect(QTimer*&, void(QTimer::*)(QTimer::QPrivateSignal), MyClass::MyClass()::<lambda()>)'. What should I do?

              YashpalY Offline
              YashpalY Offline
              Yashpal
              wrote on last edited by
              #5

              @Donald-Duck Probably, you are using older version of Qt on your Linux that doesn't understand the newer format of QObject::connect statement. Try with older format.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Donald Duck
                wrote on last edited by
                #6

                I found the problem. I had to activate C++11, which is not activated be default. In Qt Creator, I had to add the following line:

                CONFIG += c++11
                
                JohanSoloJ 1 Reply Last reply
                1
                • D Donald Duck

                  I found the problem. I had to activate C++11, which is not activated be default. In Qt Creator, I had to add the following line:

                  CONFIG += c++11
                  
                  JohanSoloJ Offline
                  JohanSoloJ Offline
                  JohanSolo
                  wrote on last edited by
                  #7

                  @Donald-Duck said in No matching function for call to QObject::connect:

                  I found the problem. I had to activate C++11, which is not activated be default. In Qt Creator, I had to add the following line:

                  CONFIG += c++11
                  

                  Note that this behaviour is gcc's default, QtCreator is simply an IDE, not a compiler. Using a .pro file without this config with VS 2013+ would most probably have worked.

                  `They did not know it was impossible, so they did it.'
                  -- Mark Twain

                  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