新建一个搜索窗口,setLayout出现问题!!!
本人是菜鸟,如果有什么建议和意见,请指出,万分感激!!
// AutoSearchDlg.h
class AutoSearchDlg : public QDialog
{
Q_OBJECT
public:
AutoSearchDlg(QWidget *parent = 0);
public slots:
void SetupDialog();
private:
QLabel *textLabel;
QLabel *ipLabel;
QLineEdit *ipLineEdit;
QDialogButtonBox *buttonBox;
QPushButton *findButton;
QGridLayout *buttomLayout;
QVBoxLayout *mainLayout;
};
// AutoSearchDlg.cpp
AutoSearchDlg::AutoSearchDlg(QWidget *parent)
: QDialog(parent)
{
}
void AutoSearchDlg::SetupDialog()
{
textLabel = new QLabel(tr("Please input IP address and mask for network search.\n"));
ipLabel = new QLabel(tr("IP Address:"));
ipLineEdit = new QLineEdit;
ipLabel->setBuddy(ipLineEdit);
findButton = new QPushButton(tr("&Find"));
findButton->setDefault(true);
buttomLayout = new QGridLayout;
buttomLayout->addWidget(ipLabel, 0, 0);
buttomLayout->addWidget(ipLineEdit, 0, 1);
buttomLayout->addWidget(buttonBox,2,2);
mainLayout = new QVBoxLayout;
mainLayout->addWidget(textLabel);
mainLayout->addLayout(buttomLayout);
setLayout(mainLayout);
exec();
}
// mainwindwo.cpp
#include "AutoSearchDlg.h"
MainWindow::MainWindow()
{
// 创建菜单工具栏等操作 ……
// 触发的Action
AutoSearchDlg *autoSearchDlg = new AutoSearchDlg();
AutoSearchAct = new QAction(tr("Auto Search"), this);
connect(AutoSearchAct, SIGNAL(triggered()), autoSearchDlg, SLOT(SetupDialog()));
}
运行,点击按钮触发时候,第一次是正常的
关闭搜索窗口后,从主窗口再次触发
就出现以下问题
QWidget::setLayout: Attempting to set QLayout "" on AutoSearchDlg "", which already has a layout
有知道原因的吗?谢谢
[ 此帖被bingogo在2009-05-25 15:41重新编辑 ]