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.7k 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.
  • 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
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #29

          Ok, all good then (with your Qt) :)
          It should be no different inserting a QGraphicsView subclass

          NiagarerN 1 Reply Last reply
          0
          • mrjjM mrjj

            Ok, all good then (with your Qt) :)
            It should be no different inserting a QGraphicsView subclass

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

            @mrjj
            I'm not sure if I understood that correctly...
            In the old project GraphWidget is just a normal Widget. Here it is a QGraphicsView. Where is the mattering difference?

            mrjjM P 2 Replies Last reply
            0
            • NiagarerN Niagarer

              @mrjj
              I'm not sure if I understood that correctly...
              In the old project GraphWidget is just a normal Widget. Here it is a QGraphicsView. Where is the mattering difference?

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

              @Niagarer

              Its not. 100% the same.
              class QGraphicsView : public QAbstractScrollArea
              class QAbstractScrollArea : public QFrame
              class QFrame : public QWidget

              NiagarerN 1 Reply Last reply
              1
              • mrjjM mrjj

                @Niagarer

                Its not. 100% the same.
                class QGraphicsView : public QAbstractScrollArea
                class QAbstractScrollArea : public QFrame
                class QFrame : public QWidget

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

                @mrjj
                Ok... So it is because of the QGraphicsView
                And what could I do to fix that?

                mrjjM 1 Reply Last reply
                0
                • NiagarerN Niagarer

                  @mrjj
                  I'm not sure if I understood that correctly...
                  In the old project GraphWidget is just a normal Widget. Here it is a QGraphicsView. Where is the mattering difference?

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

                  @Niagarer here I see that you add your Widget to vector after you are trying to get one from

                  //ui->allNodes_scrollArea->setWidget( allNodesWidgets[ui->Graph->currentIndex()] );     // !? PROBLEM !?
                      allNodesWidgets.append(allNodesWidget);
                  
                  1 Reply Last reply
                  0
                  • NiagarerN Niagarer

                    @mrjj
                    Ok... So it is because of the QGraphicsView
                    And what could I do to fix that?

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

                    @Niagarer
                    No, its not due to QGraphicsView.
                    its something else.

                    NiagarerN 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      @Niagarer
                      No, its not due to QGraphicsView.
                      its something else.

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

                      @mrjj
                      Ok >.<
                      can you give me suggestions what else I could try?

                      mrjjM 1 Reply Last reply
                      0
                      • NiagarerN Niagarer

                        @mrjj
                        Ok >.<
                        can you give me suggestions what else I could try?

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

                        @Niagarer

                        Im not really sure "what is not working".
                        You seem to crash your list when no tab is active
                        ui->Graph->currentIndex() returns -1 in this case.

                        Other than that im not sure what you ask?

                        NiagarerN 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          @Niagarer

                          Im not really sure "what is not working".
                          You seem to crash your list when no tab is active
                          ui->Graph->currentIndex() returns -1 in this case.

                          Other than that im not sure what you ask?

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

                          @mrjj
                          No, yes the list thing was a mistake but the actual problem is still that In this project I event can not do this:

                              ui->Graph->addTab(new QPushButton("blobb"),"tab");
                          

                          And I have no idea why
                          And exactely this is the line where it crashes
                          When I do this:

                              qDebug() << "first";
                              ui->Graph->addTab(new QPushButton("blobb"),"tab");
                              qDebug() << "second";
                          

                          I get is this:

                          first
                          ASSERT failure in QVector<T>::operator[]: "index out of range"
                          
                          mrjjM 1 Reply Last reply
                          0
                          • NiagarerN Niagarer

                            @mrjj
                            No, yes the list thing was a mistake but the actual problem is still that In this project I event can not do this:

                                ui->Graph->addTab(new QPushButton("blobb"),"tab");
                            

                            And I have no idea why
                            And exactely this is the line where it crashes
                            When I do this:

                                qDebug() << "first";
                                ui->Graph->addTab(new QPushButton("blobb"),"tab");
                                qDebug() << "second";
                            

                            I get is this:

                            first
                            ASSERT failure in QVector<T>::operator[]: "index out of range"
                            
                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #38

                            @Niagarer

                            Is ui->Graph the tabWidget ?
                            You do call setupUI() in (mainwin) constructor ? to setup ui before use?

                            Also addTab is the build in func? you did NOT add a new function your self?

                            NiagarerN 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @Niagarer

                              Is ui->Graph the tabWidget ?
                              You do call setupUI() in (mainwin) constructor ? to setup ui before use?

                              Also addTab is the build in func? you did NOT add a new function your self?

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

                              @mrjj
                              Yes, the constructor of MainWindow now looks like this:

                              MainWindow::MainWindow(QWidget *parent) :
                                  QMainWindow(parent),
                                  ui(new Ui::MainWindow)
                              {
                                  qDebug() << "Start of MainWindow Constructor";
                              
                                  ui->setupUi(this);
                              
                                  tabCounter = 0;
                              
                                  qDebug() << "first";
                                  ui->Graph->addTab(new QPushButton("blobb"),"tab");
                                  qDebug() << "second";
                              
                                  qDebug() << "End of MainWindow Constructor";
                              }
                              

                              No I did not build a new addTab()-function
                              Yes the ui->Graph is the TabGidget

                              mrjjM 1 Reply Last reply
                              0
                              • NiagarerN Niagarer

                                @mrjj
                                Yes, the constructor of MainWindow now looks like this:

                                MainWindow::MainWindow(QWidget *parent) :
                                    QMainWindow(parent),
                                    ui(new Ui::MainWindow)
                                {
                                    qDebug() << "Start of MainWindow Constructor";
                                
                                    ui->setupUi(this);
                                
                                    tabCounter = 0;
                                
                                    qDebug() << "first";
                                    ui->Graph->addTab(new QPushButton("blobb"),"tab");
                                    qDebug() << "second";
                                
                                    qDebug() << "End of MainWindow Constructor";
                                }
                                

                                No I did not build a new addTab()-function
                                Yes the ui->Graph is the TabGidget

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

                                @Niagarer
                                Really strange then.
                                All seems ok.

                                If you zip and upload project , I can try and see if it crash here

                                NiagarerN 2 Replies Last reply
                                1
                                • mrjjM mrjj

                                  @Niagarer
                                  Really strange then.
                                  All seems ok.

                                  If you zip and upload project , I can try and see if it crash here

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

                                  @mrjj
                                  Ok, thank you. Give me a minute

                                  1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @Niagarer
                                    Really strange then.
                                    All seems ok.

                                    If you zip and upload project , I can try and see if it crash here

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

                                    @mrjj
                                    https://www.dropbox.com/s/so6z2p3otpti2mo/GraphicalProgrammer_3.zip?dl=0

                                    mrjjM 1 Reply Last reply
                                    0
                                    • NiagarerN Niagarer

                                      @mrjj
                                      https://www.dropbox.com/s/so6z2p3otpti2mo/GraphicalProgrammer_3.zip?dl=0

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

                                      @Niagarer
                                      Super. Found it

                                      When you insert new tab. A signal is sent (currentChanged)

                                      you catch signal ( its auto connected )
                                      on_Graph_currentChanged(int index)
                                      and then kill yourself with allNodesWidgets[index] as index is 100% surely out of bounds as nothing added to
                                      allNodesWidgets yet.

                                      void MainWindow::on_Graph_currentChanged(int index)
                                      {
                                      ui->allNodes_scrollArea->setWidget( allNodesWidgets[index] ); <<<< this gives the actual error
                                      }

                                      NiagarerN 1 Reply Last reply
                                      3
                                      • mrjjM mrjj

                                        @Niagarer
                                        Super. Found it

                                        When you insert new tab. A signal is sent (currentChanged)

                                        you catch signal ( its auto connected )
                                        on_Graph_currentChanged(int index)
                                        and then kill yourself with allNodesWidgets[index] as index is 100% surely out of bounds as nothing added to
                                        allNodesWidgets yet.

                                        void MainWindow::on_Graph_currentChanged(int index)
                                        {
                                        ui->allNodes_scrollArea->setWidget( allNodesWidgets[index] ); <<<< this gives the actual error
                                        }

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

                                        @mrjj
                                        Pheww...
                                        Yes, you are right, now it works.
                                        Thanks A LOT man!
                                        Now I can sleep again... >.<

                                        mrjjM 1 Reply Last reply
                                        1
                                        • NiagarerN Niagarer

                                          @mrjj
                                          Pheww...
                                          Yes, you are right, now it works.
                                          Thanks A LOT man!
                                          Now I can sleep again... >.<

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

                                          @Niagarer
                                          :)
                                          Super.
                                          It took 10 secs with breakpoint to find.
                                          If larger program, it would been one of the nasty ones. :)

                                          Good sleep then ;)

                                          1 Reply Last reply
                                          1

                                          • Login

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