首页| 论坛| 消息

标题:请教QT designer 的使用问题?
作者:anye529
日期:2006-10-13 16:14
内容:

请问在QT designer 中如何向类中添加公有数据类型,例如 QTimer *timer 或者QSocket *socket
等?好像没有办法在在界面上拖动这类控件自动生成,如果在.ui文件夹下的隐藏文件中的类声明文件添加,make以后又会消失,请各位高手赐教。


#1 [浪漫天使 10-14 00:18]
顾名思义,designer 只是用来设计界面控件的,对于非界面的元素,只好自己手动添加。至于你提到的问题,qt文档里面讨论了三种方法,我记得只有两种:继承和组合。
在qt3中的desinger是可以添加变量了。其实在mfc中一些非界面的成员也是要自己添加的
下面是qt420 帮助文档里面的原话,希望对你有帮助
For example, here's the uic output for a simple helloworld.ui form (some details were removed for simplicity):
namespace Ui {
class HelloWorld
{
public:
QVBoxLayout *vboxLayout;
QPushButton *pushButton;
void setupUi(QWidget *HelloWorld)
{
HelloWorld->setObjectName(QString::fromUtf8("HelloWorld"));
vboxLayout = new QVBoxLayout(HelloWorld);
vboxLayout->setObjectName(QString::fromUtf8("vboxLayout"));
pushButton = new QPushButton(HelloWorld);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
vboxLayout->addWidget(pushButton);
retranslateUi(HelloWorld);
}
};
}
In this case, the main container was specified to be a QWidget (or any subclass of QWidget). Had we started with a QMainWindow template in Qt Designer, setupUi()'s parameter would be of type QMainWindow.
There are two ways to create an instance of our form. One approach is to create an instance of the Ui::HelloWorld class, an instance of the main container (a plain QWidget), and call setupUi():
#include
#include
#include "ui_helloworld.h" // defines Ui::HelloWorld
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget w;
Ui::HelloWorld ui;
ui.setupUi(&w);
w.show();
return app.exec();
}

The second approach is to inherit from both the Ui::HelloWorld class and the main container, and to..

回复 发表
主题 版块