QObject::connect name conflict with winsock
-
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 onBut 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?
-
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 onBut 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?
@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); }); -
@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); });@jsulm Many thanks for the advise. It helped me.
Btw, I found how to solve the original issue with name conflict . I had to changeif (connect(clientSocket, (SOCKADDR *) &clientAddress, sizeOfClientAddress)) {to
if ( :: connect(clientSocket, (SOCKADDR *) &clientAddress, sizeOfClientAddress)) {this solved the namespaces problem
-
@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); });@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 ;-)