Results 1 to 7 of 7

Thread: Help with this message

  1. #1
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Help with this message

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help with this message

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Help with this message

    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);
    }
    ¿¿

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Help with this message

    Yes, you pass "chat" to two layout constructors.

    Cheers,
    _

  5. #5
    Join Date
    Sep 2016
    Posts
    78
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default Re: Help with this message

    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.
    Last edited by davinciomare; 1st October 2016 at 18:58.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Help with this message

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Help with this message

    Qt Code:
    1. QWidget *chat=new Qwidget;
    2. QPushButton *botonChatEnviar = new QPushButton("Enviar",chat);
    3. QLineEdit *enviarChatTexto= new QLineEdit(chat);
    4. QPlainTextEdit *salidaChatTexto = new QPlainTextEdit(chat);
    5.  
    6.  
    7. capa->addwidget(botonChatEnviar);
    8. capa->addwidget(enviarChatTexto);
    9. capa->addwidget(salidaChatTexto);
    10.  
    11. this->setLayout(capa);
    To copy to clipboard, switch view to plain text mode 

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Help message box
    By ChrisOfBristol in forum Newbie
    Replies: 4
    Last Post: 2nd April 2015, 14:30
  2. Call GUI(message box) from Dll
    By Dilshad in forum Newbie
    Replies: 1
    Last Post: 24th July 2012, 14:40
  3. Replies: 4
    Last Post: 12th October 2008, 13:47
  4. Get Windows message
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2008, 10:28
  5. what does these debug message mean?
    By wesley in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 27th February 2008, 07:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.