Qt Quick 프로젝트가 있고 방금 일부 소스 파일을 추가했습니다. 빌드를 시도 할 때 다음과 같은 오류 메시지가 나타납니다.라이브러리에는 QApplication이 필요합니다. Qt Quick 프로젝트에서 QApplication을 사용하는 방법은 무엇입니까?
QWidget: Cannot create a QWidget without QApplication
Qt Quick 프로젝트가 있으므로 QGuiApplication을 사용합니다. QApplication은 QGuiApplication의 하위 클래스입니다. 새로 추가 된 소스에서 QApplication을 사용하려면 어떻게합니까? 또는 Qt Quick와 QWidget을 가지고있을 때 어떻게 해결할 수 있습니까?
원본 파일은 그래프를 표시하는 QCustomPlot 라이브러리입니다.
편집 :
MAIN.CPP :
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
//Register C++ classes with QML
qmlRegisterType<Bluetooth>("Bluetooth", 1, 0, "Bluetooth");
//Set start QML file
viewer.setMainQmlFile(QStringLiteral("qml/test/main.qml"));
//New Code:
// generate some data:
QWidget widget;
QCustomPlot * customPlot = new QCustomPlot(&widget);
QVector<double> x(101), y(101); // initialize with entries 0..100
for (int i=0; i<101; ++i)
{
x[i] = i/50.0 - 1; // x goes from -1 to 1
y[i] = x[i]*x[i]; // let's plot a quadratic function
}
// create graph and assign data to it:
customPlot->addGraph();
customPlot->graph(0)->setData(x, y);
// give the axes some labels:
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
// set axes ranges, so we see all data:
customPlot->xAxis->setRange(-1, 1);
customPlot->yAxis->setRange(0, 1);
customPlot->replot();
//New Code End
//Show GUI
viewer.showExpanded();
return app.exec();
}
오류 :
QML debugging is enabled. Only use this in a safe environment.
QWidget: Cannot create a QWidget without QApplication
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
당신은 어떤 QWidgets가 생성되기 전에의 QApplication 인스턴스를 생성해야합니다. – drescherjm
@drescherjm : QApplication과 QGuiApplication 루프를 모두 main()에 둘 수 있습니까? – Phat
아니요. QWidgets보다 먼저 QGuiApplication 인스턴스를 작성해야한다는 의미였습니다. – drescherjm