テキストボックスに文字を追加するには?

Qtでテキストボックスにテキストを追加するには、setText() メソッドを使用してテキストを特定の文字列に設定できます。以下は簡単なサンプルコードです。

#include <QtWidgets>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget window;
    QVBoxLayout layout(&window);

    QLabel label;
    label.setText("Hello, World!");

    QLineEdit textEdit;
    textEdit.setText("Qt Textbox");

    layout.addWidget(&label);
    layout.addWidget(&textEdit);

    window.setLayout(&layout);
    window.show();

    return app.exec();
}

上の例では、メソッドsetText()を用いて、ラベル(label)とテキストボックス(textEdit)のテキストを指定した文字列に設定しています。コードを実行すると、ラベルとテキストボックスにそれぞれのテキストが表示されます。

bannerAds