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. QStack pop() does not remove the item from the stack
Qt 6.11 is out! See what's new in the release blog

QStack pop() does not remove the item from the stack

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • D Offline
    D Offline
    ddze
    wrote on last edited by
    #1

    Hi,

                    QStack <QColor> stackColors; // QStack declaration ... push 2 values onto the stack
    
                    qDebug()<<" getColor count a "<<cell->getStackColors().count(); // out -> 2 
                    cell->getStackColors().removeLast();  // should reduce the count to 1 
                    qDebug()<<" getColor count b "<<cell->getStackColors().count();  // again out -> 2 
    

    So apparently the removeLast() does not reduce the number of items on the stack. I tried pop() and nothing. Have I misunderstood the concept since the documents explain that the removeLast "Removes the last item in the vector" , (stack).

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi

      QStack <QColor> stackColors; 
        stackColors.push(QColor(0,0,0));
        stackColors.push(QColor(222,222,222));
        qDebug() << " getColor count a " << stackColors.count(); // out -> 2
        stackColors.removeLast();  // should reduce the count to 1
        qDebug() << " getColor count b " << stackColors.count(); // again out -> 2
      

      gives
      getColor count a 2
      getColor count b 1

      so my guess is that cell->getStackColors() returns a COPY of your list.
      If you are not using & in return type, this might be why.
      (it creates a copy , not returning the original list)

      D 1 Reply Last reply
      2
      • mrjjM mrjj

        hi

        QStack <QColor> stackColors; 
          stackColors.push(QColor(0,0,0));
          stackColors.push(QColor(222,222,222));
          qDebug() << " getColor count a " << stackColors.count(); // out -> 2
          stackColors.removeLast();  // should reduce the count to 1
          qDebug() << " getColor count b " << stackColors.count(); // again out -> 2
        

        gives
        getColor count a 2
        getColor count b 1

        so my guess is that cell->getStackColors() returns a COPY of your list.
        If you are not using & in return type, this might be why.
        (it creates a copy , not returning the original list)

        D Offline
        D Offline
        ddze
        wrote on last edited by
        #3

        @mrjj ,

        You people are incredibly good.

        Thank you so much.

        1 Reply Last reply
        1

        • Login

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