简体   繁体   中英

(Qt) QTabWidget et QPlainTextEdit

Good evening,

I am stuck on a problem with QTabWidget. I would like to recover the content of QPlainTextEdit which is only found in the tab chosen and displayed this in the terminal using the btnT button.

EditorText::EditorText()
{
    QHBoxLayout *layout = new QHBoxLayout(this);
    onglets = new QTabWidget;
    QPushButton *btn = new QPushButton("Hello");
    QPushButton *btnT = new QPushButton("TWO");

    connect(btn, SIGNAL(clicked()), this, SLOT(addOnglet()));
    connect(btnT, SIGNAL(clicked()), this, SLOT(addText()));

    layout->addWidget(btn);
    layout->addWidget(btnT);
    layout->addWidget(onglets);
}

void EditorText::addOnglet()
{
    onglets->addTab(new QPlainTextEdit, QString::number(onglets->count() + 1));

    onglets->setCurrentIndex(onglets->count() - 1);
}

void EditorText::addText()
{
    QPlainTextEdit *w = onglets->widget(onglets->currentIndex())->findChild<QPlainTextEdit *>();
    std::cout << w->toPlainText().toStdString() << std::endl;
}

Thanks in advance: D.

I was able to solve it here is the code for people who have the same problem :D. -->

void EditorText::addTabPrincipal()
{
    QWidget *m_widPrin  = new QWidget;
    QPlainTextEdit *aa = new QPlainTextEdit(m_widPrin );

    m_principalTabOnglets->addTab(m_widPrin , QString::number(m_principalTabOnglets->count() + 1));

    m_principalTabOnglets->setCurrentIndex(m_principalTabOnglets->count() - 1);
}

void EditorText::abstPrintTerminalText()
{
    QPlainTextEdit *w = m_principalTabOnglets->widget(m_principalTabOnglets->currentIndex())->findChild<QPlainTextEdit *>();
    std::cout << w->toPlainText().toStdString() << std::endl;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM