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 store the text entered in LineEdit?
Qt 6.11 is out! See what's new in the release blog

How to store the text entered in LineEdit?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.7k 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.
  • NewMoonN Offline
    NewMoonN Offline
    NewMoon
    wrote on last edited by
    #1

    I am a new bie to Qt. I hope you guys can help me to solve my problem. I want to store (save) the user entered text of a QLineEdit. I want to store this in a string list. Also i have to check whether the user entered text is already stored. If the text is already stored then it should not store again. Please help...

    New Moon....

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

      You can add a QLineEdit and QPushButton in your mainwindow and connect the QPushButton clicked() signal to a slot.

      @void MainWindow::on_addButton_clicked()
      {
      QString text = ui->lineEdit->text();

      if (!list.contains(text))
          list.append(text);
      

      }@

      You can also check for CaseSensitivity.

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Well, Qt is great is doing something like that.
        Connect the signal of the LineEdit editingFinished() to a slot in your class (probably your main window.
        @
        connect(ui->lineEditName, SIGNAL(editingFinished()), this, SLOT(MyReceivingSlot())
        @
        btw: the ui-> comes from the designer created widget.

        The code for that slot:
        @
        void MainWindow::MyReceivingSlot(void)
        {
        if (m_MyList.contains(ui->lineEditName.text()) == false)
        {
        m_MyList.apped(ui->lineEditName.text();
        }
        }
        @
        Of course the m_MyList is a member of the MainWindow class.
        btw the MyReceivingSlot must be a slot and not a standard private or public function. (just saying it because your a rooky here ;-))
        That is basic how you could do it.
        Greetz

        Greetz, Jeroen

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          If this answered your question, edit your post and add [SOLVED] to the title.

          Greetz, Jeroen

          1 Reply Last reply
          0

          • Login

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