Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Something wrong with pointer I think

    General and Desktop
    2
    3
    604
    Loading More Posts
    • 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.
    • F
      Francknos last edited by

      Hi,
      Here is my code :

      @
      for(int i=0 ; i<8 ;i+=2)
      {
      QLabel *l = new QLabel(QString::number(i));
      _codeAxe.append(l);
      }
      @

      _codeAxe is :
      @QVector<QLabel*> _codeAxe;@

      I dont understand why all QLabel into _codeAxe have the same pointer ?
      exemple of result of Qdegub:
      QVector(QLabel(0x12fd1390) , QLabel(0x12fd1390) , QLabel(0x12fd1390) , QLabel(0x12fd1390) , QLabel(0x12fd1390) , QLabel(0x12fd1390) , QLabel(0x12fd1390) )

      1 Reply Last reply Reply Quote 0
      • T
        Tectu last edited by

        The QDebug output you show does not seem to be in sync with the code you pasted. In your code, the for-loop would be executed four times but your debug output shows seven elements.
        What happened there?

        A general notel, there is no need to go complex, just use this:

        @_codeAxe.append(new QLabel(QString::number(i));@

        ~ Tectu

        1 Reply Last reply Reply Quote 0
        • F
          Francknos last edited by

          I don't understand why
          @
          QLabel *l = new QLabel(QString::number(i));
          _codeAxe.append(l);
          @

          Doesn't work ... because I use the same thing with an other object which works very well.

          But I'll put @_codeAxe.append(new QLabel(QString::number(i));@

          thx

          1 Reply Last reply Reply Quote 0
          • First post
            Last post