Qt奇怪报错总结
导言
整理了下在qtweight转qml项目时的一些奇怪报错:
sogoupinyin\Components\程序异常结束。
注释了之后在之后还会出现0x0000000070310B1E (Qt5Cored.dll)处(位于 XTKJqml.exe 中)引发的异常: 0xC0000005: 读取位置 0xFFFFFFFFFFFFFFFF
原来:
//这里巨神奇,只有cout两次,ccy2,ccy3的数值才正确
cout << ccy1 << endl << ccy2 << endl << ccy3 << endl;
int wlen = 0;
if (L == 0) {
wlen = (Blen - 6) / 2;
}
else {
UINT16 temp;
fread(&temp, sizeof(UINT16), L, rfid);
wlen = (Blen - 6 - 2 * L) / 2;
}
INT16 * ysda = new INT16[wlen];
//vector<INT16> ys_da;
fread(ysda, sizeof(INT16), wlen, rfid);
vector<INT16> ys_da;
for (int i = 0; i < wlen; i++) {
ys_da.push_back(ysda[i]);
}
cout << ysda[0] << endl << ysda[1] << endl << ysda[2] << endl;
cout << ccy1 << endl << ccy2 << endl << ccy3 << endl;
修正后:
int wlen = 0;
if (L == 0) {
wlen = (Blen - 6) / 2;
}
else {
UINT16 * temp = new UINT16[L];
fread(temp, sizeof(UINT16), L, rfid);
wlen = (Blen - 6 - 2 * L) / 2;
delete temp;
}
INT16 * ysda = new INT16[wlen];
fread(ysda, sizeof(INT16), wlen, rfid);
vector<INT16> ys_da;
for (int i = 0; i < wlen; i++) {
ys_da.push_back(ysda[i]);
}
0x00007FF96FF3B922 (ig9icd64.dll)处(位于 ZTKJ_V3.exe 中)引发的异常: 0xC0000005: 读取位置 0xFFFFFFFFFFFFFFFF 时发生访问冲突。
之前的mian.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
之后的mian.cpp
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include "include/sates.h"
int main(int argc, char *argv[])
{
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
#if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QApplication app(argc, argv);
app.setWindowIcon(QIcon(":/pic/logoHJ.ico"));
qmlRegisterType<Sates>("an.qml.SatesMouble", 1, 0, "Sates");
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setVersion(3, 2);
format.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(format);
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
注意
该文章仅个人学习使用,欢迎大家一起交流学习