Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject::connect name conflict with winsock
Qt 6.12 LTS is out! See what's new in the release blog

QObject::connect name conflict with winsock

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.2k Views 1 Watching
  • 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.
  • 6 Offline
    6 Offline
    63350541
    wrote on last edited by 63350541
    #1

    In my client class I've got such piece of code checking if client is connected

    void Client::connectToServer() {
        setUpClientAddress();
        initializeSocket();
    
        if (connect(clientSocket, (SOCKADDR *) &clientAddress, sizeOfClientAddress)) {
            std::cout << "Failed to connect" << std::endl;
            return;
        } else { // so on 
    

    But when I'm trying to generate GUI and bind click event I' facing the following issue - "No matching member function for call to 'connect'"

    class Client : public QObject{
    
    /*some code before*/ 
    for (const std::string &s: guiInfo) {
                QPushButton *button = new QPushButton(QString::fromStdString(s));
                const QSize BUTTON_SIZE = QSize(40, 40);
                button->setFixedSize(BUTTON_SIZE);
                QObject::connect(button, SIGNAL(clicked()), this, SLOT(requestScene(s)));
    
                layout->addWidget(button);
            }
    /*some code after*/ 
    

    How to solve this conflict? Does winsock_32 have his namespace, so it could be solved by QObject::connect and WinSock32::connect?

    jsulmJ 1 Reply Last reply
    0
    • 6 63350541

      In my client class I've got such piece of code checking if client is connected

      void Client::connectToServer() {
          setUpClientAddress();
          initializeSocket();
      
          if (connect(clientSocket, (SOCKADDR *) &clientAddress, sizeOfClientAddress)) {
              std::cout << "Failed to connect" << std::endl;
              return;
          } else { // so on 
      

      But when I'm trying to generate GUI and bind click event I' facing the following issue - "No matching member function for call to 'connect'"

      class Client : public QObject{
      
      /*some code before*/ 
      for (const std::string &s: guiInfo) {
                  QPushButton *button = new QPushButton(QString::fromStdString(s));
                  const QSize BUTTON_SIZE = QSize(40, 40);
                  button->setFixedSize(BUTTON_SIZE);
                  QObject::connect(button, SIGNAL(clicked()), this, SLOT(requestScene(s)));
      
                  layout->addWidget(button);
              }
      /*some code after*/ 
      

      How to solve this conflict? Does winsock_32 have his namespace, so it could be solved by QObject::connect and WinSock32::connect?

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

      @63350541 said in QObject::connect name conflict with winsock:

      SLOT(requestScene(s)

      This is wrong: you can't pass parameters (s in this case) when connecting. Parameters are passed when emitting the signal. If you want to define the parameter when you connect use new connect syntax and C++ lambda:

      QObject::connect(button, &QPushButton::clicked, [this, s]() { requestScene(s); });
      

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

      6 S 2 Replies Last reply
      4
      • jsulmJ jsulm

        @63350541 said in QObject::connect name conflict with winsock:

        SLOT(requestScene(s)

        This is wrong: you can't pass parameters (s in this case) when connecting. Parameters are passed when emitting the signal. If you want to define the parameter when you connect use new connect syntax and C++ lambda:

        QObject::connect(button, &QPushButton::clicked, [this, s]() { requestScene(s); });
        
        6 Offline
        6 Offline
        63350541
        wrote on last edited by
        #3

        @jsulm Many thanks for the advise. It helped me.
        Btw, I found how to solve the original issue with name conflict . I had to change

            if (connect(clientSocket, (SOCKADDR *) &clientAddress, sizeOfClientAddress)) {
        

        to

            if ( :: connect(clientSocket, (SOCKADDR *) &clientAddress, sizeOfClientAddress)) {
        

        this solved the namespaces problem

        1 Reply Last reply
        3
        • jsulmJ jsulm

          @63350541 said in QObject::connect name conflict with winsock:

          SLOT(requestScene(s)

          This is wrong: you can't pass parameters (s in this case) when connecting. Parameters are passed when emitting the signal. If you want to define the parameter when you connect use new connect syntax and C++ lambda:

          QObject::connect(button, &QPushButton::clicked, [this, s]() { requestScene(s); });
          
          S Offline
          S Offline
          SimonSchroeder
          wrote on last edited by
          #4

          @jsulm said in QObject::connect name conflict with winsock:

          QObject::connect(button, &QPushButton::clicked, [this, s]() { requestScene(s); });

          I'd like to add one tiny thing to this. Most of the time you will rely on signal/slot connections to be disconnected automatically. In the normal syntax this is done when either the sender or receiver object are deleted. Unfortunately, this version of the lambda syntax circumvents this. However, you can (and should) provide a context object:

          QObject::connect(button, &QPushButton::clicked, this, [this,s]() { requestScene(s); });
          

          I am still trying for me to always follow this advice when using lambdas ;-)

          1 Reply Last reply
          2

          • Login

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