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.3k 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.
  • 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