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. Something wrong with pointer I think
QtWS25 Last Chance

Something wrong with pointer I think

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 744 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.
  • F Offline
    F Offline
    Francknos
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      Tectu
      wrote on last edited by
      #2

      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
      0
      • F Offline
        F Offline
        Francknos
        wrote on last edited by
        #3

        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
        0

        • Login

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