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. Create a vector of QPushButtons?

Create a vector of QPushButtons?

Scheduled Pinned Locked Moved Solved General and Desktop
vectorqpushbutton
3 Posts 2 Posters 1.9k 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.
  • L Offline
    L Offline
    legitnameyo
    wrote on 6 Feb 2019, 18:43 last edited by
    #1

    I want to create a list of buttons, each with unique names and colors. I believe that a vector would be good for this, since I can just push back objects "for ever", without the space limit of arrays. My code is

    QPushButton *crt = new QPushButton(ui->frame_with_btns);
    
            crt->setText(QString("text"));
            crt->move(0, 30*total_btn);
            crt->resize(186, 30);
            crt->setStyleSheet("QPushButton{background-color:red;}");
            crt->topLevelWidget();
            crt->show();
            v_btn.push_back(*crt);
            total_btn += 1;
    

    and I've defined a vector in my .h file as

    std::vector<QPushButton> v_btn;
    int total_btn = 0;
    

    which gives me the error

    error: call to deleted constructor of 'QPushButton' ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
    
    J 1 Reply Last reply 6 Feb 2019, 18:52
    0
    • L legitnameyo
      6 Feb 2019, 18:43

      I want to create a list of buttons, each with unique names and colors. I believe that a vector would be good for this, since I can just push back objects "for ever", without the space limit of arrays. My code is

      QPushButton *crt = new QPushButton(ui->frame_with_btns);
      
              crt->setText(QString("text"));
              crt->move(0, 30*total_btn);
              crt->resize(186, 30);
              crt->setStyleSheet("QPushButton{background-color:red;}");
              crt->topLevelWidget();
              crt->show();
              v_btn.push_back(*crt);
              total_btn += 1;
      

      and I've defined a vector in my .h file as

      std::vector<QPushButton> v_btn;
      int total_btn = 0;
      

      which gives me the error

      error: call to deleted constructor of 'QPushButton' ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
      
      J Offline
      J Offline
      JonB
      wrote on 6 Feb 2019, 18:52 last edited by
      #2

      @legitnameyo
      I'm not a C++-er. But should you not be creating a vector of the pointers to the push buttons you are creating?

      std::vector<QPushButton *> v_btn;
      ...
      v_btn.push_back(crt);
      

      What you're trying to do will try to copy the QPushButtons, which Qt does not allow.

      Is that right?

      1 Reply Last reply
      4
      • L Offline
        L Offline
        legitnameyo
        wrote on 6 Feb 2019, 18:55 last edited by
        #3

        that solved it! Thanks!

        1 Reply Last reply
        0

        1/3

        6 Feb 2019, 18:43

        • Login

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