标题:QT下面能否从一个form调用另一个form,例如一个对话框调用另一个对话框
作者:yangshaoxing
日期:2006-11-30 12:12
内容:
QT下面能否从一个form调用另一个form,例如一个对话框调用另一个对话框
例如:
第一个对话框:
dialog1.h:
#ifndef DIALOG1_H
#define DIALOG1_H
#include
#include
#include
#include
#include
#include
#include
class Dialog1 : public QDialog
{
Q_OBJECT
public:
Dialog1();
private:
QPushButton *pushButton;
QLabel *label;
private:
void showdialog2();
};
#endif // DIALOG1_H
dialog1.cpp
#include
#include
#include
#include
#include
#include
#include
#include "dialog1.h"
#include "dialog2.h"
Dialog1::Dialog1()
{
pushButton = new QPushButton(this);
pushButton->setGeometry(QRect(30, 240, 361, 23));
label = new QLabel(this);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(10, 10, 351, 71));
QFont font;
font.setPointSize(15);
font.setBold(true);
font.setWeight(75);
label->setFont(font);
setWindowTitle(QApplication::translate("Dialog1", "Dialog1", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("Dialog1", "click to show dialog2", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("Dialog1", "this is dialog1.", 0, QApplication::UnicodeUTF8));
QSize size(400, 300);
size = size.expandedTo(minimumSizeHint());
resize(size);
connect(pushButton, SIGNAL(clicked()),this,SLOT(showdialog2));
}
void Dialog1::showdialog2()//在这里调用第二个对话框
{
Dialog2 dialog2;
dialog2.exec();
}
第 ..
#1 [浪漫天使 11-30 12:48]
请楼主搜索一下论坛的帖子,其他网友已经提到过相关的问题。
#2 [忘记业 12-01 11:29]
利用信号与槽的方法可以解决!!
#3 [yangshaoxing 12-02 08:29]
我把dialog1.h改为:
#ifndef DIALOG1_H
#define DIALOG1_H
#include
#include
#include
#include
#include
#include
#include
#include "dialog2.h"
class QPushButton;
class QLabel;
class Dialog2;
class Dialog1 : public QDialog
{
Q_OBJECT
public:
Dialog1(QWidget *fck = 0);
private:
QPushButton *pushButton;
QLabel *label;
Dialog2 *dialog2;
private:
void showdialog2();
};
#endif // DIALOG1_H
把显示dialog2的函数改为:
void Dialog1::showdialog2()
{
//Dialog2 *dialog2;
dialog2=new Dialog2(this);
dialog2->show();
}
结果还是一样。上贴说利用信号与槽的方法可以解决,请问如何解决?
#4 [drifthat 12-02 16:13]
楼上的兄弟,你首先得把showdialog2声明成slot,然后connect那句话也是错的,应该写成:
connect(pushButton, SIGNAL(clicked()),this,SLOT(showdialog2()));
#5 [忘记业 12-02 16:37]
就是按4楼的哥们说的那样就可以了,在槽内将 dialog2实例化就行了