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. QVector::size() makes program crash
Forum Updated to NodeBB v4.3 + New Features

QVector::size() makes program crash

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 447 Views
  • 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.
  • J Offline
    J Offline
    Jakob Clausen
    wrote on 20 Apr 2022, 08:37 last edited by
    #1

    Hi all.

    I have a function that looks like this

    void IconWidget::changePixmap(int newIndex)
    {
        if (newIndex < pixmaps.size())
            index = newIndex;
    
        updatePixmap();
    }
    

    pixmaps is declared as

    typedef struct
    {
        Pixmap::Index index;
        QPixmap lightNormal;
        QPixmap lightActive;
        QPixmap darkNormal;
        QPixmap darkActive;
    } PixmapItem;
    
    QVector<PixmapItem> pixmaps;
    

    When I call. QVector::size(), then the program crashes with a segfault.
    Any ideas?

    6101b3ea-8766-4a11-8ae3-c5531c787ba2-image.png

    J 1 Reply Last reply 20 Apr 2022, 08:42
    0
    • J Jakob Clausen
      20 Apr 2022, 08:37

      Hi all.

      I have a function that looks like this

      void IconWidget::changePixmap(int newIndex)
      {
          if (newIndex < pixmaps.size())
              index = newIndex;
      
          updatePixmap();
      }
      

      pixmaps is declared as

      typedef struct
      {
          Pixmap::Index index;
          QPixmap lightNormal;
          QPixmap lightActive;
          QPixmap darkNormal;
          QPixmap darkActive;
      } PixmapItem;
      
      QVector<PixmapItem> pixmaps;
      

      When I call. QVector::size(), then the program crashes with a segfault.
      Any ideas?

      6101b3ea-8766-4a11-8ae3-c5531c787ba2-image.png

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 20 Apr 2022, 08:42 last edited by
      #2

      @Jakob-Clausen I would say, it's not breaking on the size call, but on the function entry point, on the very first thing it has to do with a member variable.

      from top right I would say your IconWidget instance is invalid (null)


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • J Offline
        J Offline
        Jakob Clausen
        wrote on 20 Apr 2022, 08:47 last edited by
        #3

        That is interesting.
        If I replace the first line in the function with something like

        qDebug() << "hello";

        Then it also crashes. If you are right, is this what is to be expected?

        J 1 Reply Last reply 20 Apr 2022, 08:48
        0
        • J Jakob Clausen
          20 Apr 2022, 08:47

          That is interesting.
          If I replace the first line in the function with something like

          qDebug() << "hello";

          Then it also crashes. If you are right, is this what is to be expected?

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 20 Apr 2022, 08:48 last edited by
          #4

          @Jakob-Clausen jepp


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jakob Clausen
            wrote on 20 Apr 2022, 10:58 last edited by
            #5

            Ok. Maybe not quite that.
            But your input helped me track down what the problem really was.
            Thank you very much for your help.

            1 Reply Last reply
            0

            5/5

            20 Apr 2022, 10:58

            • Login

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