How to take text input from a user and use it as a value within code
Unsolved
General and Desktop
-
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="https://www.youtube.com/watch?v=km1AjXF2OcM";
QDesktopServices::openUrl(QUrl(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!
-
Use QLineEdit and look for appropriate signal and slots
MyWidget.h
MyWidget {QLineEdit *edit;
}MyWidget::MyWidget() {
edit = new QLineEdit;
edit.show()
connect(edit,SIGNAL(editFinished()),this,SLOT(readValue()));
}void MyWidget::readValue(){
QString text = edit.text();
qDebug() << " Text = " << text << endl;
} -
You can also have a look at QInputDialog