Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStatusbar problem with insertWidget
Forum Updated to NodeBB v4.3 + New Features

QStatusbar problem with insertWidget

Scheduled Pinned Locked Moved General and Desktop
17 Posts 3 Posters 8.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KennedyDayala
    wrote on last edited by
    #1

    "QStatusBar::insertWidget: Index out of range (1), appending widget" when will this warning is given ??...can somebosy guide me ??

    EDIT: splitted this as it is an own topic, Gerolf

    Never Ever Give Up

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      can you please post some code, what you do? the error message without code is something like looking in a crystal ball to solve your problem.

      One idea from the crystal ball:

      you have not added any widgets and call QStatusBar::insertWidget(1, ...). This will fail, as index 0 is not filled.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KennedyDayala
        wrote on last edited by
        #3

        @void IDT_MainWindow::on_treeWidgetDrives_itemClicked(QTreeWidgetItem* item, int column)
        {
        //QPalette *p = new QPalette();
        //p->setColor(QPalette::Active,static_castQPalette::ColorRole(9),QColor(Qt:gray));

        ui->textEditDriverDetails->clear();
        strDisk = item->text(column);
        //ui->textEditDriverDetails->setText(strDisk);
        QLabel *label1=new QLabel();
        QLabel *label2=new QLabel();
        QLabel *label3=new QLabel();
        
        //QString strDir = "";
        double dFree,dTotal;
        
        getFreeTotalSpace(strDisk,dTotal,dFree);
        QVariant var1( dTotal );
        QVariant var2( dFree );
        QString tmp1 = var1.toString();
        QString tmp2 = var2.toString();
        
        QFont texteditFont("Tokyo");
        texteditFont.setPointSize(16);
        texteditFont.setBold(true);
        
        ui->textEditDriverDetails->setFont(texteditFont);
        //ui->textEditDriverDetails->setPalette(p);
        
        ui->textEditDriverDetails->insertPlainText("Drive Name : "+strDisk);
        ui->textEditDriverDetails->insertPlainText("\n\n\n");
        ui->textEditDriverDetails->insertPlainText("Total Size : "+tmp1+" GB");
        ui->textEditDriverDetails->insertPlainText("\n\n\n");
        ui->textEditDriverDetails->insertPlainText("Available Size : "+tmp2+" GB");
        
        statusBar()->insertWidget(1,label1,20);
        statusBar()->insertWidget(2,label2,20);
        statusBar()->insertWidget(3,label3,20);
        
        label1->setText("<font color='red'>Drive :</font>");
        label2->setText("<font color='blue'>Total Size :</font>");
        label3->setText("<font color='green'>Free Size :</font>");
        
        ///QColor color()
        

        }
        @

        ...and one more problem i am getting is that these three panes are getting created each time i click on tree item :-(

        Never Ever Give Up

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          So, don't create them in response to such a click, but only once! In your click, you only need to set the values, not create the complete QLabel.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            And it is exaclty what I mentiond, use

            @
            statusBar()->insertWidget(0,label1,20);
            statusBar()->insertWidget(1,label2,20);
            statusBar()->insertWidget(2,label3,20);
            @

            from the docs:

            bq. Inserts the given widget at the given index to this status bar, reparenting the widget if it isn't already a child of this QStatusBar object. If index is out of range, the widget is appended (in which case it is the actual index of the widget that is returned).

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • K Offline
              K Offline
              KennedyDayala
              wrote on last edited by
              #6

              shall I create them in my constructor and use them in every click ?/

              Never Ever Give Up

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="Thomas Kennedy" date="1302608291"]shall I create them in my constructor and use them in every click ?/[/quote]
                Yes. Or, better yet, update them when the selection changes, not when you click them.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  KennedyDayala
                  wrote on last edited by
                  #8

                  oops..my app gets hanged...

                  i did like this

                  declared .h file
                  @
                  private:
                  QLabel *label1;
                  QLabel *label2;
                  QLabel *label3;
                  @

                  invoked and attached to statusbar in constructor
                  @
                  IDT_MainWindow::IDT_MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::IDT_MainWindow)

                  {
                  //...........
                  //.................

                  label1=new QLabel();
                  label2=new QLabel();
                  label3=new QLabel();
                  
                  statusBar()->insertWidget(0,label1,20);
                  statusBar()->insertWidget(1,label2,20);
                  statusBar()->insertWidget(2,label3,20);
                  

                  }
                  @

                  updating/displaying on treewidget item clicked
                  @
                  void IDT_MainWindow::on_treeWidgetDrives_itemClicked(QTreeWidgetItem* item, int column)
                  {
                  //...........
                  //...........
                  label1->setText("<font color='red'>Drive :</font>");
                  label2->setText("<font color='blue'>Total Size :</font>");
                  label3->setText("<font color='green'>Free Size :</font>");
                  }
                  @

                  ............please lemme know my wrong steps

                  Never Ever Give Up

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    [quote author="Thomas Kennedy" date="1302672610"]oops..my app gets hanged...
                    [/quote]

                    That is way too vague. What happens exactly? What does your debugger tell you?
                    The snippets you posted look fine at first sight, but because they are not very complete, there is no way to tell if they trigger a problem anyway.

                    Note that I find it weird that you set the fixed label text when clicking on an item in your tree. I was assuming you wanted to set some dynamic text based your click.

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      KennedyDayala
                      wrote on last edited by
                      #10

                      yes Adre..my intentions is to set the test dynamically...I just tried with that sample text with color..but why should this code causing to crash the app ??

                      "IDT_DEmo_UI.exe has stopped working
                      A Problem caused the program to stop working correctly.Windows will close the program and notify you if a solutions is available."

                      ...this is the message window with a "Close Program" button I am getting.

                      Never Ever Give Up

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        KennedyDayala
                        wrote on last edited by
                        #11

                        "E:\Bose\Qt playground\IDT_Demo_UI-build-desktop\debug\IDT_Demo_UI.exe exited with code 255"
                        ..debugger report

                        Never Ever Give Up

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          OK, so now, run your code through a debugger. That will tell you where the code crashed and why it did so. We cannot possibly guess based on the snippets you showed us.

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            KennedyDayala
                            wrote on last edited by
                            #13

                            through a debugger means with breakpoint ?

                            Never Ever Give Up

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on last edited by
                              #14

                              No, no breakpoint needed, your crash will supply that point :-)

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                KennedyDayala
                                wrote on last edited by
                                #15

                                I am running the app in debug mode only...after getting that app message I am not being taken to any code line...app is just getting closed !!!...how to get the appropriate trace ??

                                Never Ever Give Up

                                1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  KennedyDayala
                                  wrote on last edited by
                                  #16

                                  and also how to get get the error code description ??

                                  Never Ever Give Up

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    andre
                                    wrote on last edited by
                                    #17

                                    Are you using QtCreator?
                                    If so, run your program by pressing F5 (or pressing the green arrow with the little bug on it on the bottom left of your screen).

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved