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. Why VerticalHeaderItem cause crit.error
Qt 6.11 is out! See what's new in the release blog

Why VerticalHeaderItem cause crit.error

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 1.4k 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by
    #1

    When i add any action to my VertHItem - in runtime it cause crit error and the program stop working. I've included QHeaderView, certain Item indeed exist, but i simply can't set text for it:

    if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
    

    That code assures that item at '0' exist and it's label is 1, which is true, it 1 by default in my app.

    P.S. here is it in documentation

    jsulmJ aha_1980A 2 Replies Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You should check its not NULL
      try
      qDebug() << "item = " << tabWidGuide.verticalHeaderItem(0);

      1 Reply Last reply
      6
      • EngelardE Engelard

        When i add any action to my VertHItem - in runtime it cause crit error and the program stop working. I've included QHeaderView, certain Item indeed exist, but i simply can't set text for it:

        if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
        

        That code assures that item at '0' exist and it's label is 1, which is true, it 1 by default in my app.

        P.S. here is it in documentation

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Engelard said in Why VerticalHeaderItem cause crit.error:

        if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);

        To add to @mrjj : you should ALWAYS check pointers before dereferencing them!

        if(tabWidGuide.verticalHeaderItem(0) && tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        JonBJ 1 Reply Last reply
        7
        • EngelardE Engelard

          When i add any action to my VertHItem - in runtime it cause crit error and the program stop working. I've included QHeaderView, certain Item indeed exist, but i simply can't set text for it:

          if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
          

          That code assures that item at '0' exist and it's label is 1, which is true, it 1 by default in my app.

          P.S. here is it in documentation

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Engelard

          And that's exactly the difference between pointers and references you have to understand.

          Pointers have to be checked against nullptr before de-referencing, references can always be used.

          Qt has to stay free or it will die.

          1 Reply Last reply
          6
          • jsulmJ jsulm

            @Engelard said in Why VerticalHeaderItem cause crit.error:

            if(tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);

            To add to @mrjj : you should ALWAYS check pointers before dereferencing them!

            if(tabWidGuide.verticalHeaderItem(0) && tabWidGuide.verticalHeaderItem(0)->text()=="1") tabWidGuide.verticalHeaderItem(0)->setBackground(Qt::red);
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @jsulm , @aha_1980
            I agree with your advice. However, I took the OP at his word when his question states

            [I am] certain Item indeed exist

            I shall be interested to see whether he comes back and says that pointer was NULL after all, maybe I'm too trusting...!

            1 Reply Last reply
            1
            • EngelardE Offline
              EngelardE Offline
              Engelard
              wrote on last edited by
              #6

              Tnx for all advices for checking item, now it shows that header does'nt exist. BUT. Why it exist in the app, and it returning like it does'nt?

              aha_1980A 1 Reply Last reply
              0
              • EngelardE Engelard

                Tnx for all advices for checking item, now it shows that header does'nt exist. BUT. Why it exist in the app, and it returning like it does'nt?

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Engelard

                Why it exist in the app, and it returning like it does'nt?

                • How do you set it?
                • Do you set it before your read it back?

                Qt has to stay free or it will die.

                EngelardE 1 Reply Last reply
                0
                • aha_1980A aha_1980

                  @Engelard

                  Why it exist in the app, and it returning like it does'nt?

                  • How do you set it?
                  • Do you set it before your read it back?
                  EngelardE Offline
                  EngelardE Offline
                  Engelard
                  wrote on last edited by
                  #8

                  @aha_1980 i didn't set anything, i assume that it set by default, so why would i set it..

                  aha_1980A 1 Reply Last reply
                  0
                  • EngelardE Engelard

                    @aha_1980 i didn't set anything, i assume that it set by default, so why would i set it..

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Engelard said in Why VerticalHeaderItem cause crit.error:

                    i assume that it set by default,

                    It isn't.

                    Qt has to stay free or it will die.

                    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