Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 Qt(和 C++)的新手。我有一个简单的问题:怎么了?
#include <QCoreApplication> #include <QtNetwork/QLocalServer> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QLocalServer* x = new QLocalServer(this); return a.exec(); }
感谢您的建议。
你的问题是这个(双关语):
QLocalServer* x = new QLocalServer(this);
this在非静态类成员函数之外无效。main() 不是成员函数,因此this不存在。您可以改为传递 NULL 指针,以表示该对象不应有父对象:
this
QLocalServer* x = new QLocalServer(NULL);
不要忘记在项目文件的QT变量中添加网络模块。例如:
QT
QT += OTHER_MODULES_YOU_USE_HERE network