Important: Please read the Qt Code of Conduct -

Create a vector of QPushButtons?

  • 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->move(0, 30*total_btn);
            crt->resize(186, 30);
            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)...);

  • @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;

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

    Is that right?

  • that solved it! Thanks!

Log in to reply