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

                                          • Login

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