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. connecting a signal from a QTcpSocket isn't working

connecting a signal from a QTcpSocket isn't working

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

    I'm learning how to use QTcpSockets and servers so I'm setting up my test classes to play around with. However on my "client" app, I'm trying to connect the signal "connected" from the socket to a timer. I get the error

     error: no matching function for call to ‘SocketTestApp::connect(QTcpSocket*&, void (QAbstractSocket::*)(), QTimer*&, <unresolved overloaded function type>)’
         QObject::connect(_socket, &QTcpSocket::connected, _timer, &QTimer::start);
                                                                                 ^
    

    But that doesn't make any sense, see the below code. The first QObject::connect has no problems, but the second one gives that error. I added the QObject in hopes it would fix it but it didn't. What is going on here? It looks like it thinks the second connect statement is calling QTcpSocket::connect, but I'm explicitly telling it to use QObject::connect.

    SocketTestApp::SocketTestApp(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::SocketTestApp),
        _socket(new QTcpSocket(this)),
        _timer(new QTimer(this))
    {
        ui->setupUi(this);
    
        QObject::connect(_timer, &QTimer::timeout, this, &SocketTestApp::transmitMessage);
        QObject::connect(_socket, &QTcpSocket::connected, _timer, &QTimer::start);
    
        _timer->setInterval(3000);
    }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      It is becz overloaded start() methods in QTimer.

      Try to using - QObject::connect(_socket, SIGNAL(connected()), _timer,SLOT( start());

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • G Offline
        G Offline
        graniteDev
        wrote on last edited by
        #3

        Yup, that fixed it. Please explain how you determined that from the error. As my reading of the error was wrong.

        jsulmJ 1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Just look at the Qt Creator error. It should have given you more error than this. It must be explicit saying multiple overloaded methods. I don't know which one.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • G graniteDev

            Yup, that fixed it. Please explain how you determined that from the error. As my reading of the error was wrong.

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

            @graniteDev Explanation: QTimer has two start() methods: one without parameters and one with a parameter. If you do it like

            connect(_socket, &QTcpSocket::connected, _timer, &QTimer::start);
            

            the compiler doesn't know which one you mean.
            That's why it says "<unresolved overloaded function type>"
            You can see here what you can do in such a situation: https://riptutorial.com/qt/example/17048/connecting-overloaded-signals-slots

            connect(_socket, &QTcpSocket::connected, _timer, qOverload<>(&QTimer::start));
            

            For qOverload you need to make sure your compiler supports C++14 and that it is activated.
            If you only have C++11 you can do

            connect(_socket, &QTcpSocket::connected, _timer, QOverload<>::of((&QTimer::start));
            

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

            1 Reply Last reply
            3

            • Login

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