qt 6 我想单独写一个工具类,不使用QT的ui界面等
想直接先把槽连接上
connect(socket, &QTcpSocket::connected, this,net_socket_con_solt);
直接报错
Use of undeclared identifier 'connect'; did you mean 'QAbstractSocket::connect'?
In template: cannot initialize a parameter of type 'const QObject *' with an lvalue of type 'const typename QtPrivate::FunctionPointer<void (gin_net_socket_tcp::*)()>::Object *' (aka 'const gin_net_socket_tcp *')
原因是因为,这个只是c++的基本类,没有connect这种说法
需要在一开始的类中继承QObject就可以使用
class net_socket_tcp:public QObject
{
Q_OBJECT
就可以正常的运行
参考
https://blog.csdn.net/m0_61629312/article/details/133820817