[Qt-interest] setLayout warning ?

Malyushytsky, Alex alex at wai.com
Tue Jun 2 04:57:46 CEST 2009


Read documentation?

void QWidget::setLayout ( QLayout * layout )
Sets the layout manager for this widget to layout.
If there already is a layout manager installed on this widget, QWidget won't let you install another.
You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout.

Regards,
        Alex

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Gan Xiebin
Sent: Sunday, May 24, 2009 11:57 PM
To: qt-interest
Subject: [Qt-interest] setLayout warning ?

Hi,all.

I got a problem when i use "setLayout" to complete my " find dialog".

code:
warning

// 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?

Thanks!
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list