2013-10-24 36 views
0

如何在Qt Creator中创建多个UI表单并将它们链接起来? 我想在我的mainwindow.ui中有一个按钮,当它被触发时,我想要显示其他的UI。 我该怎么办?Qt项目中的多个UI

我有两个Qt的表单类:

  1. 主窗口
  2. mainwindow2

我在main.cpp中尝试这种代码:

#include "mainwindow.h" 
#include "mainwindow2.h" 
#include <QApplication> 

int main(int argc, char *argv[]) 
{ 
QApplication a(argc, argv); 
MainWindow w; 
w.show(); 
MainWindow2 w2; 
w2.show(); 

return a.exec(); 
} 

,但出现这样的错误:

main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __thiscall MainWindow2::~MainWindow2(void)" ([email protected]@[email protected]) referenced in function _main

main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall MainWindow2::MainWindow2(class QWidget *)" ([email protected]@[email protected]@@@Z) referenced in function _main

release\testtest.exe:-1: error: LNK1120: 2 unresolved externals

+0

HTH http://qt-project.org/doc/qt-4.8/designer-using-custom-widgets.html – Tab

+2

你定义构造函数和你的'MainWindow2'类中的析构函数? – thuga

回答

-1

看看slots并与其他UI.show()/ otherUI.hide()一起玩,如果你想要基本的交互。

对于类似器问题:从msdnhere

When you created the project, you made the wrong choice of application type. When asked whether your project was a console application or a windows application or a DLL or a static library, you made the wrong chose windows application (wrong choice).

Go back, start over again, go to File -> New -> Project -> Win32 Console Application -> name your app -> click next -> click application settings.

For the application type, make sure Console Application is selected (this step is the vital step).

The main for a windows application is called WinMain, for a DLL is called DllMain, for a .NET application is called Main(cli::array ^), and a static library doesn't have a main. Only in a console app is main called main

+0

如何添加另一个ui并使用它。我尝试添加“Qt Designer Form Class”和“Qt Designer Form”,但我不知道如何定义它们。在课堂上,我试图显示otherui,但发生链接错误。 –

+0

我添加了另一个类,并试图显示它在我的main.cpp中,但再次发生链接错误 –

+0

@ Aidin.T哪个错误?将它添加到您的问题中,并尽可能添加一点代码 –