C++ QMLApplicationViewer仅多个实例首先显示窗口
我对QTQuick1.1(QT4.8)有问题。我有一个主类,我在其中引用QMLApplicationViewer,它显示窗口。我还调用了一个类,该类应该用另一个QML文件显示另一个类,但它没有显示。但是,会显示调试消息。 这是我的密码:C++ QMLApplicationViewer仅多个实例首先显示窗口,c++,qml,qt-quick,qt4.8,C++,Qml,Qt Quick,Qt4.8,我对QTQuick1.1(QT4.8)有问题。我有一个主类,我在其中引用QMLApplicationViewer,它显示窗口。我还调用了一个类,该类应该用另一个QML文件显示另一个类,但它没有显示。但是,会显示调试消息。 这是我的密码: AnotherWindow::AnotherWindow(QString notImportant) { } void AnotherWindow::create(){ QmlApplicationViewer view; qDebug()<<"db
AnotherWindow::AnotherWindow(QString notImportant)
{
}
void AnotherWindow::create(){
QmlApplicationViewer view;
qDebug()<<"dbug: CWCReate";
view.addImportPath(QLatin1String("modules"));
view.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
view.setMainQmlFile(QString("instanceOfAnotherWindow.qml"));
view.showExpanded();
qDebug()<<"dbug: show";
}
提前谢谢。这一行是麻烦:
QmlApplicationViewer视图代码>
想想你在这里干什么
Q.在程序的整个生命周期内(希望如此)在函数中实例化一个对象
Q.局部变量的生存期是多少
Q.当函数退出时,该变量会发生什么情况
哦!,但这基本上可以正常工作,这也是一个函数
Q.那么,主函数的生命周期是什么
解决方案:使此对象在程序的整个生命周期内都可用。指针和动态分配内存怎么样?让这个指针成为类的数据成员怎么样?在程序结束之前,main不会“退出”,是吗
QmlApplicationViewer view;
view.addImportPath(QLatin1String("modules"));
view.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
view.setMainQmlFile(QLatin1String("/main.qml"));
view.setFixedSize(360,600);
AnotherWindow *c = new AnotherWindow("notImportantHere");
c->create();
view.showExpanded();
return app->exec();
}