PDA

View Full Version : Help with this message



davinciomare
30th September 2016, 01:05
Hi i did one project in qt but show me this message:
QLayout: Attempting to add QLayout "" to QWidget "", which already has a layout

How i can solve this issue. Thanks in advance.

wysota
30th September 2016, 08:13
Don't add a second layout to a widget that already has one. Either delete the first one before setting another or reuse the existing layout. It depends on what you are trying to achieve.

davinciomare
30th September 2016, 11:25
i think the issue is this:

void MainWindow::generarVentanaChat()
{
/** Crea una ventana de chat **/
this->chat = new QWidget(0,Qt::CustomizeWindowHint);
this->capa = new QVBoxLayout(chat);
this->capaHorizontal = new QHBoxLayout(chat);
this->botonChatEnviar = new QPushButton("Enviar",chat);
this->enviarChatTexto = new QLineEdit(chat);
salidaChatTexto = new QPlainTextEdit(chat);
capa->addWidget(salidaChatTexto);
capaHorizontal->addWidget(enviarChatTexto);
capaHorizontal->addWidget(botonChatEnviar);
capa->addLayout(capaHorizontal);
}
¿¿

anda_skoa
30th September 2016, 11:36
Yes, you pass "chat" to two layout constructors.

Cheers,
_

davinciomare
1st October 2016, 17:58
QWidget *chat=new Qwidget;
QPushButton *botonChatEnviar = new QPushButton("Enviar",chat);
QLineEdit *enviarChatTexto= new QLineEdit(chat);
QPlainTextEdit *salidaChatTexto = new QPlainTextEdit(chat);

QVBoxLayout *capa = new QVBoxLayout;

capa->addwidget(botonChatEnviar);
capa->addwidget(enviarChatTexto);
capa->addwidget(salidaChatTexto);

this->setLayout(capa);
When i do this show me errors. I tried to update.

wysota
1st October 2016, 19:32
What are the errors? The only thing you should have changed in your original code was to not pass the root widget twice into layout constructors. You can either pass null (skip the argument) or pass the parent layout.

d_stranz
1st October 2016, 22:16
QWidget *chat=new Qwidget;
QPushButton *botonChatEnviar = new QPushButton("Enviar",chat);
QLineEdit *enviarChatTexto= new QLineEdit(chat);
QPlainTextEdit *salidaChatTexto = new QPlainTextEdit(chat);

QVBoxLayout *capa = new QVBoxLayout;

capa->addwidget(botonChatEnviar);
capa->addwidget(enviarChatTexto);
capa->addwidget(salidaChatTexto);

this->setLayout(capa);

You are creating all of your GUI widgets as children of "chat", and adding them to the "capa" layout. Then for some unknown reason, you set the layout on "this" (whatever "this" is), and not "chat", the widget you said was the parent.

If you want the layout to apply to the "this" widget, then don't create the QWidget instance ("chat"), create all of the GUI widgets as children of "this" (or with no parent at all, since adding them to the layout will make the layout their parent).

I am happy to see that you have learned not to put QUOTE tags around your code, now please learn how to put CODE tags instead. My signature block explains how.