V
V
Vladimir Korshunov2021-12-24 15:47:44
Qt
Vladimir Korshunov, 2021-12-24 15:47:44

Why can't I add my Widget to Layout (Qt)?

I wrote such a simple Widget:

class but_indicate : public QWidget
{
    Q_OBJECT
public:
    explicit but_indicate(QWidget *parent = nullptr);

private:
    QLabel *lb1, *lb2;

public slots:
    void buttonPressed();
    void buttonReleased();
};


Here is its constructor:
but_indicate::but_indicate(QWidget *parent) : QWidget(parent)
{
    QHBoxLayout* tbLO = new QHBoxLayout;
    lb1 = new QLabel("Simple button is not pressed.");
    lb1->setFrameStyle(QFrame::Box);
    lb1->setLineWidth(1);
    lb2 = new QLabel("Toggle button is not pressed.");
    lb2->setFrameStyle(QFrame::Box);
    lb2->setLineWidth(1);
    tbLO->addWidget(lb1);
    tbLO->addWidget(lb2);
    setLayout(tbLO);
}


Can I add it to QVBoxLayout at all? If I use my Widget alone then it works great:
but_indicate* b = new but_indicate;
    b->show();

If I want to add it to QVBoxLayout, then I get the error "'but_indicate' does not refer to a value":
QVBoxLayout* mainLO = new QVBoxLayout;
    mainLO->addWidget(but_indicate); //вот тут ошибка

What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korshunov, 2021-12-25
@GashhLab

I accidentally wrote the name of the class instead of the name of the variable in the last line, there were no problems in the implementation of the class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question