我在跟着一篇博客使用QML搭建TCP客户端后,发现程序Debug,Release版本编译都能通过,但运行崩溃,只有一行提示
The process was ended forcefully.
想问问大家为什么会出现这个问题,怎么解决呢?
博客链接:
QtQuick网络socket编程Demo
https://blog.csdn.net/zusi_csdn/article/details/80975898
在重写后,我把main函数中加载QML的方式换成了使用QQuickView,程序就能加载出来了。用QQmlEngine还是会提示程序异常结束,这是为什么呢?
使用QQuickView
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<TcpSocket>("An.qt.myTcpSocket",1,0,"TcpSocket");
QQuickView view;
view.setSource(QUrl("qrc:/main.qml"));
view.show();
return app.exec();
}
使用QQmlEngine
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<TcpSocket>("An.qt.myTcpSocket",1,0,"TcpSocket");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}