Important: Please read the Qt Code of Conduct -

How to take text input from a user and use it as a value within code

  • Hi Guys, here's a code within a button. The link is for example purposes and is SFW (YouTube Chill lounge album).

    void MainWindow::on_pushButton_clicked()
    QString link="";

    I'd like to take text input from a user to replace the URL. I'm new to QT and trying it out. Any help would be greatly appreciated. I just can't seem to find anything on this! There's a slight time constraint, so I haven't had time to do in-depth study yet (pushing for a new career path so I have to do this on my own limited time :( ) As I said, any help would be greatly appreciated!

  • Qt Champions 2017

    Use QLineEdit and look for appropriate signal and slots

    MyWidget {

    QLineEdit *edit;

    MyWidget::MyWidget() {
    edit = new QLineEdit;

    void MyWidget::readValue(){
    QString text = edit.text();
    qDebug() << " Text = " << text << endl;

  • @CyberSynth

    You can also have a look at QInputDialog

Log in to reply