当前位置: 技术问答>linux和unix
qt多窗体控件的访问
来源: 互联网 发布时间:2016-06-13
本文导语: 新手啊求救啊!~~~ form1里面就一个按钮(pushButton1); form2里面有 pushButton5,textLabel1, form1里面的按钮访问form2里面的控件,怎么弄的啊? #include "form2.h" extern Form2 *w2; void Form1::pushButton1_clicked() { w2->pushButton5->se...
新手啊求救啊!~~~
form1里面就一个按钮(pushButton1);
form2里面有 pushButton5,textLabel1,
form1里面的按钮访问form2里面的控件,怎么弄的啊?
#include "form2.h"
extern Form2 *w2;
void Form1::pushButton1_clicked()
{
w2->pushButton5->setText("222"); //这个可以
w2->textLabel1->setText("22222222"); //这个不可以
w2->show();
}
.ui/../form1.ui.h:19: 错误:invalid use of undefined type ‘struct QLabel’
.ui/form2.h:19: 错误:forward declaration of ‘struct QLabel’
make: *** [.obj/form1.o] 错误 1
为什么啊?我只弄过builder,QT完全不同啊,或者推荐本好书给我啊 跪谢了
form1里面就一个按钮(pushButton1);
form2里面有 pushButton5,textLabel1,
form1里面的按钮访问form2里面的控件,怎么弄的啊?
#include "form2.h"
extern Form2 *w2;
void Form1::pushButton1_clicked()
{
w2->pushButton5->setText("222"); //这个可以
w2->textLabel1->setText("22222222"); //这个不可以
w2->show();
}
.ui/../form1.ui.h:19: 错误:invalid use of undefined type ‘struct QLabel’
.ui/form2.h:19: 错误:forward declaration of ‘struct QLabel’
make: *** [.obj/form1.o] 错误 1
为什么啊?我只弄过builder,QT完全不同啊,或者推荐本好书给我啊 跪谢了
|
Form1:.....
{
private:
Form2 *w2;
public:
set_target(Form2 *w2);
};
//这是我的main.cpp
#include
#include "form1.h"
#include "form2.h"
Form2 *w2;
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Form1 w;
w.show();
w2 = new Form2;
w.set_target(w2); //以后再w里调用w.w2指针就可以了
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}
|
#include "form2.h"
#include
#include
extern Form2 *w2;
void Form1::pushButton1_clicked()
{
w2->pushButton5->setText("222"); //这个可以
w2->textLabel1->setText("22222222"); //这个不可以
w2->show();
}
红色部分, 加上头文件就可以了。
#include
#include
extern Form2 *w2;
void Form1::pushButton1_clicked()
{
w2->pushButton5->setText("222"); //这个可以
w2->textLabel1->setText("22222222"); //这个不可以
w2->show();
}
红色部分, 加上头文件就可以了。
|
1。 是的, 用什么控件就必须加什么头文件。
2。 这个其实无所谓, C++ 的一些特性而已。