A
A
alexey_abramov2015-04-06 22:13:37
Qt
alexey_abramov, 2015-04-06 22:13:37

Qtextedit - how to work with setText, setHtml as slots?

I study qt at the initial stage.
There is a code (slightly modified from Max Schlee's book):

#include <QtWidgets>

// ----------------------------------------------------------------------
int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    QTextEdit* txt = new QTextEdit;
    QTextEdit* txttwo = new QTextEdit;
    QWidget    wgt;
    QLabel* lbl = new QLabel;
   QString stri = "123";
    txt->setHtml("<HTML>"
                "<BODY BGCOLOR=MAGENTA>"
                "<H2><CENTER>Gnome Poem 3: Magic Magic</CENTER></H2>"

                "<FONT COLOR=BLUE>"
                "<P ALIGN=\"center\">"
                    "<I>"
                    "Magic! Magic!<BR>"
                    "Are you here?<BR>"
                    "Abra-ca-dabra!<BR>"
                    "We appear.<BR><BR>"
                    "Magic! Magic!<BR>"
                    "Gnomes are we.<BR>"
                    "Magic gnomes<BR>"
                    "Of mystery.<BR>"
                    "..."
                    "</I>"
                "</P>"
                "</FONT>"
                "</BODY>"
                "</HTML>"
               );
    txttwo->setText(txt->toHtml());
    //QObject::connect(txttwo,SIGNAL(textChanged()), txt,SLOT(clear()));
    QObject::connect(txttwo,SIGNAL(textChanged()), txt,SLOT(setHtml(stri)));
    QHBoxLayout* pvv = new QHBoxLayout;
    pvv->addWidget(txttwo);
    pvv->addWidget(txt);
    pvv->addWidget(lbl);
    wgt.setLayout(pvv);
    wgt.show();
    return app.exec();
}

I want to write the line "123" to txt when editing txttwo
qt gives out:
QObject::connect: No such slot QTextEdit::setHtml("123") in ..\TextEdit\main.cpp:55

Some other slots work. Such as clear() for example. But the setHtml and setPlainText slots don't work. Why is that? Tell me the correct option, without writing an additional slot?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexey_abramov, 2015-04-06
@alexey_abramov

Please close the question. I found a very stupid mistake, I should have read the description of connect normally

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question