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
Forum Updated to NodeBB v4.3 + New Features

Why VerticalHeaderItem cause crit.error

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 1.1k 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.
  • E Offline
    E Offline
    Engelard
    wrote on 6 Nov 2018, 21:27 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

    J A 2 Replies Last reply 7 Nov 2018, 06:05
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 6 Nov 2018, 21:29 last edited by
      #2

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

      1 Reply Last reply
      6
      • E Engelard
        6 Nov 2018, 21:27

        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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 7 Nov 2018, 06:05 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

        J 1 Reply Last reply 7 Nov 2018, 09:35
        7
        • E Engelard
          6 Nov 2018, 21:27

          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

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 7 Nov 2018, 07:15 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
          • J jsulm
            7 Nov 2018, 06:05

            @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);
            
            J Offline
            J Offline
            JonB
            wrote on 7 Nov 2018, 09:35 last edited by JonB 11 Jul 2018, 09:35
            #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
            • E Offline
              E Offline
              Engelard
              wrote on 7 Nov 2018, 15:04 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?

              A 1 Reply Last reply 7 Nov 2018, 17:58
              0
              • E Engelard
                7 Nov 2018, 15:04

                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?

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 7 Nov 2018, 17:58 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.

                E 1 Reply Last reply 7 Nov 2018, 20:38
                0
                • A aha_1980
                  7 Nov 2018, 17:58

                  @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?
                  E Offline
                  E Offline
                  Engelard
                  wrote on 7 Nov 2018, 20:38 last edited by
                  #8

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

                  A 1 Reply Last reply 7 Nov 2018, 20:41
                  0
                  • E Engelard
                    7 Nov 2018, 20:38

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

                    A Offline
                    A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 7 Nov 2018, 20:41 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

                    2/9

                    6 Nov 2018, 21:29

                    topic:navigator.unread, 7
                    • Login

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