Results 1 to 2 of 2

Thread: Cannot do addTab in loop for

  1. #1
    Join Date
    Apr 2016
    Qt products
    Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows

    Default Cannot do addTab in loop for

    Hi everyone,

    I want to instanciate as far as I want QWidget to push into QTabWidget.
    Qt Code:
    1. QJsonArray jsonArray = jsonObject.value("Channel").toArray();
    3. for(int indexchannel(0); indexchannel < jsonArray.size(); indexchannel++){
    4. QString channel = jsonArray[indexchannel].toString();
    5. // m_console.push_back(new Console(channel));
    6. tab->addTab(new QWidget, channel);
    7. m_console.append(new Console(channel));
    8. onglet->setObjectName(QStringLiteral(channel));
    9. tab->addTab(console, console->channelName() );
    10. }
    11. // for (int widgetIndexChannel(0) ; widgetIndexChannel <m_console.size(); widgetIndexChannel++ ){
    12. // tab->addTab(,>channelName());
    13. // }
    14. tab->addTab(new QWidget, "testttt");
    15. verticalLayout->addWidget(tab);
    16. this->setCentralWidget(centralWidget);
    To copy to clipboard, switch view to plain text mode 

    according to a json file I populate my view. But I'm doing this in loop and nothing append. I feel like the addTab doesn't work in loop even though doesn't it use like that does it ?
    Sorry for my poor question.

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 777 Times in 767 Posts
    Qt products
    Windows Android

    Default Re: Cannot do addTab in loop for

    I presume you are doing this in a MainWindow constructor.

    - Why do you make the assumption that addTab() doesn't work in a loop, when you haven't even checked to see if the loop is actually being entered in the first place?

    - How do you know that your json file has been opened and read correctly into the QJsonObject?

    - You don't have any check to see that your QJsonArray instance actually -has- a size > 0

    - What's "console"? A QWidget of some sort defined outside of the loop? If so, then why are you adding it again for every pass through the loop? Do you think the "new Console" call in line 7 is going to magically assign a new value to "console"?

    Learn how to use a debugger. If you set a breakpoint at the beginning of this method, you could probably have learned immediately why your loop doesn't work as you expect.
    <=== 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. Replies: 4
    Last Post: 6th August 2011, 02:40
  2. Space Between tab and addTab Button
    By sjaideep93 in forum Newbie
    Replies: 1
    Last Post: 25th July 2011, 18:17
  3. Main loop thread loop communication
    By mcsahin in forum Qt Programming
    Replies: 7
    Last Post: 25th January 2011, 17:31
  4. AddTab button in QTabBar
    By ekapek in forum Newbie
    Replies: 2
    Last Post: 3rd July 2010, 19:51
  5. QTabWidget clicking problems after addTab()
    By DonSam in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2008, 09:28

Tags for this Thread


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.