Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to take text input from a user and use it as a value within code
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 788 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CyberSynth
    wrote on last edited by CyberSynth
    #1

    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!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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;
      }

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        @CyberSynth

        You can also have a look at QInputDialog

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved