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. [SOLVED] How to delete QLabel and QwtSlider in a std::vector
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to delete QLabel and QwtSlider in a std::vector

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.7k 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.
  • V Offline
    V Offline
    valeSimu
    wrote on 19 Jun 2014, 14:17 last edited by
    #1

    I have a std::vector filled up with QLabel and QwtSlider pointers and I would like to delete the pointers but not the vector.

    Here my code:

    @QLabel sliderSimuVarLabel;
    std::vector<QLabel
    > labelsSimuVarList;
    std::vector<QwtSlider*> slidersSimuVarList;

    int num = 3;
    for (int i=0; i<numSimuVars; ++i){

    sliderSimuVarLabel = new QLabel("Hello", Widg);
    sliderSimuVarLabel->setFont(panelFont2);

    labelsSimuVarList.push_back(new QLabelWidg));
    labelsSimuVarList[i]->setFont(panelFont2);

    slidersSimuVarList.push_back(new QwtSlider(Qt::Horizontal,Widg));

    layoutSimuPanel->addWidget(sliderSimuVarLabel,i+7,0);
    layoutSimuPanel->addWidget(slidersSimuVarList[i],i+7,1,1,5);
    layoutSimuPanel->addWidget(labelsSimuVarList[i], i+7, 7);
    }
    @

    I don't know with which method delete the pointers: clear()? deleteLater()? others?

    Thanks in advance

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jeroentjehome
      wrote on 19 Jun 2014, 14:24 last edited by
      #2

      Why do want to delete the pointer? The Widg takes ownership of the created classes. The pointers may be removed when going out of scope.
      BTW Which pointer do you want to remove?

      Greetz, Jeroen

      1 Reply Last reply
      0
      • V Offline
        V Offline
        valeSimu
        wrote on 19 Jun 2014, 14:36 last edited by
        #3

        I would like to delete the pointers in order to replace them with others QLabel and QwtSlider, when user clicks a button. I would like to remove the pointers that point each QLabel and QwtSlider in the vector. I tried something like this:

        @ if(sliderSimuVarLabel!=NULL ){
        sliderSimuVarLabel->deleteLater();
        labelsSimuVarList.clear();
        slidersSimuVarList.clear();
        }@

        or this:

        @ if(sliderSimuVarLabel!=NULL){
        sliderSimuVarLabel->deleteLater();

                for (int i=0; i>labelsSimuVarList.size();++i) {
                   labelsSimuVarList[i]->deleteLater();
                   slidersSimuVarList[i]->deleteLater();
                }
            }@
        

        but I am looking for the most safe way to delete them...

        1 Reply Last reply
        0
        • V Offline
          V Offline
          valeSimu
          wrote on 19 Jun 2014, 15:19 last edited by
          #4

          Here the solution http://stackoverflow.com/questions/24308871/how-to-delete-qlabel-and-qwtslider-in-a-stdvector?noredirect=1#comment37570892_24308871

          Thank you :-)

          1 Reply Last reply
          0

          1/4

          19 Jun 2014, 14:17

          • Login

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