[Qt-interest] (no subject)

Gan Xiebin gan.xiebin at gmail.com
Mon May 25 09:13:26 CEST 2009


It works for me !!
Thanks again!

but, where is the problem if i did it my way?


On 5/25/09, Oliver Demetz <forenbeitraege at oliverdemetz.de> wrote:
> Gan Xiebin schrieb:
>> Hi,all.
>>
>> I got a problem when i use setLayout to complete my " find dialog".
>>
>> code:
>>
>> // 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()
>> {
>> // create munu etc...
>>     AutoSearchAct = new QAction(tr("Auto Search"), this);
>>     connect(AutoSearchAct, SIGNAL(triggered()), new AutoSearchDlg(),
>> SLOT(SetupDialog()));
>>
>> }
>>
>>
>>
>>  It's fined when i first triggered the "search" action on my main window,
>> but after that, when i triggered that  action, the warning message
>> shows like that..
>> ----------
>> QWidget::setLayout: Attempting to set QLayout "" on AutoSearchDlg "",
>> which already has a layout
>> ------------
>>
>> What can I do?
>
> Export the creation of your gui prts into the constructor:
> AutoSearchDlg::AutoSearchDlg(QWidget *parent)
>  >      : QDialog(parent)
>  > {
>  > 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);
>  > }
>  >
>  > void AutoSearchDlg::SetupDialog()
>  > {
>  >
>  >
>  >
>  >      exec();
>  >
>  > }
>
> regards
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list