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 display data in lineedit from database

how to display data in lineedit from database

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 1.5k Views
  • 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.
  • R Offline
    R Offline
    Rameshguru
    wrote on last edited by J.Hilk
    #1

    I write a query in sql

    select name from student;(it display all the name from student table)

    this query successfully exected but i want to disaply lineedit to display the student names.
    dont use table view.i want to display lineedit only


    [fixed typo in the title] j.hilk

    J.HilkJ 1 Reply Last reply
    0
    • R Rameshguru

      I write a query in sql

      select name from student;(it display all the name from student table)

      this query successfully exected but i want to disaply lineedit to display the student names.
      dont use table view.i want to display lineedit only


      [fixed typo in the title] j.hilk

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      hi @Rameshguru

      I changed your title, and removed the accidental slur ;-)

      some more information would be helpful, for example
      What are you currently using to display the query results ?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rameshguru
        wrote on last edited by
        #3

        model = new QSqlTableModel(this, db);
        model->setTable("Student");

        QSqlQuery query;
        query.prepare("select FirstName from Student");
        query.exec();
        

        this is my code

        jsulmJ 1 Reply Last reply
        0
        • R Rameshguru

          model = new QSqlTableModel(this, db);
          model->setTable("Student");

          QSqlQuery query;
          query.prepare("select FirstName from Student");
          query.exec();
          

          this is my code

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Rameshguru Here https://doc.qt.io/qt-5/qsqlquery.html you can see how to get a column value as string:

           QSqlQuery query("SELECT * FROM artist");
              int fieldNo = query.record().indexOf("country");
              while (query.next()) {
                  QString country = query.value(fieldNo).toString();
                  doSomething(country);
              }
          

          You can do what ever you want with this string, for example put it into a line edit...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • R Offline
            R Offline
            Rameshguru
            wrote on last edited by
            #5

            @jslum sir thank you
            but it does not display all the data during form loading time

            JonBJ 1 Reply Last reply
            0
            • R Rameshguru

              @jslum sir thank you
              but it does not display all the data during form loading time

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Rameshguru
              The responder has shown you the necessary SQL statement to retrieve data from the database. How can you possibly expect anyone to be able to comment on your "but it does not display all the data during form loading time" if we have absolutely no idea what your code does with the result set you get back from SQL?? What sort of an answer are you expecting from us given what you've told us?

              1 Reply Last reply
              3
              • R Offline
                R Offline
                Rameshguru
                wrote on last edited by
                #7

                @jonB sir
                i create login window ,when i open the login window i wnt to display the all the username in lineedit this is my task

                J.HilkJ 1 Reply Last reply
                0
                • R Rameshguru

                  @jonB sir
                  i create login window ,when i open the login window i wnt to display the all the username in lineedit this is my task

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  @Rameshguru said in how to display data in lineedit from database:

                  @jonB sir
                  i create login window ,when i open the login window i wnt to display the all the username in lineedit this is my task

                  that task makes no sense, the nature of a LineEdit is that it's only one line of text.

                  Do you want to concat all names and display them or are you actually looking for a QComboBox


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Rameshguru
                    wrote on last edited by
                    #9

                    @J-Hilk
                    i apply Qcompleter in line edit
                    that time i type character in line edit corresponding names are displayed in the same process how to do without mention the name or charactyer

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      What about QDataWidgetMapper ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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