How to use the connect
Unsolved
General and Desktop
-
Hello, I am having a problem with my proyect, the program it is simple, I want to recieve a QString from a thread and add it to the QListWidget, but doesnt work the connect function.
ERROR: no matching function for call to 'MainWindow::connect(hiloDelSocket*&, void (hiloDelSocket::)(QString), QListWidget&, <unresolved overloaded function type>)'
hilo = new hiloDelSocket(this); connect(hilo, &hiloDelSocket::datos, ui->lista, &QListWidget::addItem);
//thread void hiloDelSocket::run(){ ZeroMemory(buffer,12); recv(sock,buffer,12,0); QString a = buffer; emit datos(a); }
//header class hiloDelSocket: public QThread { public: hiloDelSocket(QObject *parent = nullptr); signals: void datos(const QString); protected: void run() override; private: char buffer[12]; SOCKET sock; };
-
@JuanNunez There are two versions of addItem, you need to tell connect which to use.
Try:
connect(hilo, &hiloDelSocket::datos, ui->lista, QOverload<QString>::of(&QListWidget::addItem));
-
@JuanNunez said in How to use the connect:
unresolved overloaded function type
addItem has multiple overloads and the connect cont resolve which one to use.
https://doc.qt.io/qt-5/qtglobal.html#qOverload
also don't use threads. I'm 90% sure you don't know what your doing, and don't need them in the first place