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
Forum Updated to NodeBB v4.3 + New Features

how to display data in lineedit from database

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 1.6k 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.
  • R Offline
    R Offline
    Rameshguru
    wrote on 22 Feb 2019, 06:12 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 1 Reply Last reply 22 Feb 2019, 06:18
    0
    • R Rameshguru
      22 Feb 2019, 06:12

      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 Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 22 Feb 2019, 06:18 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 22 Feb 2019, 06:32 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

        J 1 Reply Last reply 22 Feb 2019, 07:32
        0
        • R Rameshguru
          22 Feb 2019, 06:32

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

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

          this is my code

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 22 Feb 2019, 07:32 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 22 Feb 2019, 08:39 last edited by
            #5

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

            J 1 Reply Last reply 22 Feb 2019, 08:53
            0
            • R Rameshguru
              22 Feb 2019, 08:39

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

              J Offline
              J Offline
              JonB
              wrote on 22 Feb 2019, 08:53 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 22 Feb 2019, 09:11 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 1 Reply Last reply 22 Feb 2019, 09:42
                0
                • R Rameshguru
                  22 Feb 2019, 09:11

                  @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 Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 22 Feb 2019, 09:42 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 22 Feb 2019, 09:55 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 22 Feb 2019, 22:24 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

                      1/10

                      22 Feb 2019, 06:12

                      • Login

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