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. ui->addTab "index out of range" !?
Qt 6.11 is out! See what's new in the release blog

ui->addTab "index out of range" !?

Scheduled Pinned Locked Moved Solved General and Desktop
45 Posts 6 Posters 13.4k Views 2 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.
  • SGaistS SGaist

    Then you already have a debugger. Just start your application in debug mode, make it crash and you'll have the stack trace.

    NiagarerN Offline
    NiagarerN Offline
    Niagarer
    wrote on last edited by
    #9

    @SGaist
    There is nothing under Stack when I am debugging...
    Are my settings wrong? I can't find anything wrong.
    Also nothing under Breakpoints, Threads, Modules, Source Files, Snapshots and Registers.
    Only the Debugger Log shows content

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #10

      Silly question but are you starting the application as usual or are you starting it with the other button which means "debug the application" ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      NiagarerN 2 Replies Last reply
      0
      • SGaistS SGaist

        Silly question but are you starting the application as usual or are you starting it with the other button which means "debug the application" ?

        NiagarerN Offline
        NiagarerN Offline
        Niagarer
        wrote on last edited by Niagarer
        #11

        @SGaist
        No, I click Start Debugging
        (but as I see now, there is Output in Modules tab when I am not closing the error message but it doesn't matter I think)

        1 Reply Last reply
        0
        • SGaistS SGaist

          Silly question but are you starting the application as usual or are you starting it with the other button which means "debug the application" ?

          NiagarerN Offline
          NiagarerN Offline
          Niagarer
          wrote on last edited by Niagarer
          #12

          @SGaist
          UPDATE
          Ok now I know, there are two points in my function, where the program crashes.
          My function:

              GraphWidget *newGraphWidget = new GraphWidget(this);
              graphWidgets.append(newGraphWidget);
              QString name = "tab " + QString::number(tabCounter);
          
              qDebug() << ui->Graph->currentIndex();
          
              //ui->Graph->addTab(newGraphWidget, "title");          // !? PROBLEM !?
          
              qDebug() << ui->Graph->currentIndex();
          
          
              tabCounter += 1;
          
              QVBoxLayout *vBoxLayout = new QVBoxLayout();
              vBoxLayout->setAlignment(Qt::AlignTop);
              QWidget *allNodesWidget = new QWidget();
              allNodesWidget->setLayout(vBoxLayout);
              //ui->allNodes_scrollArea->setWidget( allNodesWidgets[ui->Graph->currentIndex()] );     // !? PROBLEM !?
              allNodesWidgets.append(allNodesWidget);
          

          The two lines where I commented !? PROBLEM !? are the two lines. If I uncomment one of these, the program crashes with the Index error. (UPDATE: the second one is because ui->Graph->currentIndex() is -1)
          I have really no Idea what this means...
          Help please!

          1 Reply Last reply
          0
          • Vinod KuntojiV Offline
            Vinod KuntojiV Offline
            Vinod Kuntoji
            wrote on last edited by
            #13

            @Niagarer ,

            What is the initial value of tabCounter? What is the vector size?

            C++, Qt, Qt Quick Developer,
            PthinkS, Bangalore

            NiagarerN 1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #14
              This post is deleted!
              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #15

                allNodesWidgets[ui->Graph->currentIndex()]

                ui->Graph->currentIndex() is almost certainly out of bounds

                NiagarerN 1 Reply Last reply
                0
                • VRoninV VRonin

                  allNodesWidgets[ui->Graph->currentIndex()]

                  ui->Graph->currentIndex() is almost certainly out of bounds

                  NiagarerN Offline
                  NiagarerN Offline
                  Niagarer
                  wrote on last edited by Niagarer
                  #16

                  @VRonin
                  Oh, yes you are right, thanks.
                  But it unfortunately does not solve teh actual problem :/

                  1 Reply Last reply
                  0
                  • Vinod KuntojiV Vinod Kuntoji

                    @Niagarer ,

                    What is the initial value of tabCounter? What is the vector size?

                    NiagarerN Offline
                    NiagarerN Offline
                    Niagarer
                    wrote on last edited by Niagarer
                    #17

                    @Vinod-Kuntoji
                    The initial value of TabCounter is 0.
                    The vector has no specific size, it gets bigger when I add new items... what exactely do you mean?

                    P 1 Reply Last reply
                    0
                    • NiagarerN Niagarer

                      @Vinod-Kuntoji
                      The initial value of TabCounter is 0.
                      The vector has no specific size, it gets bigger when I add new items... what exactely do you mean?

                      P Offline
                      P Offline
                      Paul Busovikov
                      wrote on last edited by
                      #18

                      @Niagarer when you add new tab it do not mean that current index will be changed

                      NiagarerN 1 Reply Last reply
                      0
                      • P Paul Busovikov

                        @Niagarer when you add new tab it do not mean that current index will be changed

                        NiagarerN Offline
                        NiagarerN Offline
                        Niagarer
                        wrote on last edited by Niagarer
                        #19

                        @Paul-Busovikov
                        Yes...?
                        To get sure I wrote

                            qDebug() << ui->Graph->currentIndex();
                        

                        before and after adding a new tab

                        1 Reply Last reply
                        0
                        • NiagarerN Offline
                          NiagarerN Offline
                          Niagarer
                          wrote on last edited by
                          #20

                          To make it easier:
                          the line

                              ui->Graph->addTab(new QWidget(this), "hello");
                          

                          does not work. Doesn't matter where I call it.

                          mrjjM P 2 Replies Last reply
                          0
                          • NiagarerN Niagarer

                            To make it easier:
                            the line

                                ui->Graph->addTab(new QWidget(this), "hello");
                            

                            does not work. Doesn't matter where I call it.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #21

                            @Niagarer
                            a QWidget is not really visible. (it paints nothing)
                            Try with other type

                            NiagarerN 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @Niagarer
                              a QWidget is not really visible. (it paints nothing)
                              Try with other type

                              NiagarerN Offline
                              NiagarerN Offline
                              Niagarer
                              wrote on last edited by Niagarer
                              #22

                              @mrjj
                              Ok.
                              This also does not work:

                                  GraphWidget *newGraphWidget = new GraphWidget(this); //GraphWidget is a QGraphicsView
                                  ui->Graph->addTab(newGraphWidget, "hello");
                              
                              mrjjM 1 Reply Last reply
                              0
                              • NiagarerN Niagarer

                                @mrjj
                                Ok.
                                This also does not work:

                                    GraphWidget *newGraphWidget = new GraphWidget(this); //GraphWidget is a QGraphicsView
                                    ui->Graph->addTab(newGraphWidget, "hello");
                                
                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by mrjj
                                #23

                                @Niagarer
                                this works here
                                ui->tabWidget->addTab( new QPushButton("kkk") ,"tab" );
                                alt text

                                NiagarerN 1 Reply Last reply
                                1
                                • mrjjM mrjj

                                  @Niagarer
                                  this works here
                                  ui->tabWidget->addTab( new QPushButton("kkk") ,"tab" );
                                  alt text

                                  NiagarerN Offline
                                  NiagarerN Offline
                                  Niagarer
                                  wrote on last edited by Niagarer
                                  #24

                                  @mrjj
                                  It doesn't work in my Program... xD
                                  What the hell...
                                  0_1501510030772_Qt 3.png

                                  1 Reply Last reply
                                  0
                                  • NiagarerN Niagarer

                                    To make it easier:
                                    the line

                                        ui->Graph->addTab(new QWidget(this), "hello");
                                    

                                    does not work. Doesn't matter where I call it.

                                    P Offline
                                    P Offline
                                    Paul Busovikov
                                    wrote on last edited by
                                    #25

                                    @Niagarer yes it doesn't

                                     int index = 0;
                                         for (int i = 0; i < 10; ++i )
                                         {
                                              index = ui->tabWidget->addTab( new QWidget, "title" );
                                              qDebug() << index << "  " << ui->tabWidget->currentIndex() ;
                                         }
                                    
                                    0    0
                                    1    0
                                    2    0
                                    3    0
                                    4    0
                                    5    0
                                    6    0
                                    7    0
                                    8    0
                                    9    0
                                    
                                    NiagarerN 1 Reply Last reply
                                    0
                                    • mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #26

                                      Hi
                                      I assume you are doing other stuff in your app since it crashes.

                                      Just to be sure, your Qt is not sick.
                                      Can you try test project
                                      https://www.dropbox.com/s/tpyxmww5t98i4um/untitled39.zip?dl=0

                                      NiagarerN 1 Reply Last reply
                                      1
                                      • P Paul Busovikov

                                        @Niagarer yes it doesn't

                                         int index = 0;
                                             for (int i = 0; i < 10; ++i )
                                             {
                                                  index = ui->tabWidget->addTab( new QWidget, "title" );
                                                  qDebug() << index << "  " << ui->tabWidget->currentIndex() ;
                                             }
                                        
                                        0    0
                                        1    0
                                        2    0
                                        3    0
                                        4    0
                                        5    0
                                        6    0
                                        7    0
                                        8    0
                                        9    0
                                        
                                        NiagarerN Offline
                                        NiagarerN Offline
                                        Niagarer
                                        wrote on last edited by
                                        #27

                                        @Paul-Busovikov
                                        Oh yes, I see, I'm sorry.

                                        1 Reply Last reply
                                        0
                                        • mrjjM mrjj

                                          Hi
                                          I assume you are doing other stuff in your app since it crashes.

                                          Just to be sure, your Qt is not sick.
                                          Can you try test project
                                          https://www.dropbox.com/s/tpyxmww5t98i4um/untitled39.zip?dl=0

                                          NiagarerN Offline
                                          NiagarerN Offline
                                          Niagarer
                                          wrote on last edited by Niagarer
                                          #28

                                          @mrjj
                                          Yep, it works
                                          0_1501510743942_Qt 5.png
                                          Yes, I duplicated an old project. And now the MainWindow sould create a new tab in the tab widget called Graph with an object of my class GraphWidget (QGraphicsView). Nothing else (in the constructor).

                                          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