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. Display data real time in QT c++ from db
Forum Updated to NodeBB v4.3 + New Features

Display data real time in QT c++ from db

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.6k Views 2 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.
  • K Offline
    K Offline
    KingslyEn
    wrote on last edited by KingslyEn
    #1

    Sth like this

    The project has a page with this schema:

    There is a QlineEdit in integer and a texBox(or can be use another widget) I want to Display the relevant cell of database(sqlite with query for example:select * frome dbName where code='QlineEdit integer') in textBox, But no with a button action, real time!

    As I search it can be possible by textchange() or QLineEdit::editingFinished(), But don't know how

    Pl45m4P 1 Reply Last reply
    0
    • K KingslyEn

      Sth like this

      The project has a page with this schema:

      There is a QlineEdit in integer and a texBox(or can be use another widget) I want to Display the relevant cell of database(sqlite with query for example:select * frome dbName where code='QlineEdit integer') in textBox, But no with a button action, real time!

      As I search it can be possible by textchange() or QLineEdit::editingFinished(), But don't know how

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @KingslyEn said in Display data real time in QT c++ from db:

      As I search it can be possible by textchange() or QLineEdit::editingFinished(), But don't know how

      I would prefer the void QLineEdit::textChanged(const QString &text) signal, because to trigger editingFinished you need to press enter or leave the textEdit to make it lose the input focus.
      So textChanged is more "real time", but will fire a lot since it's send out literally every time the text changes (while typing). If you have more than one character in your QLineEdit it will produce

      f
      fo
      foo
      

      Where exactly is the problem? If you connect your function to this signal, you can take the input as argument and construct your query. After executing your query, you can set the result to your textBox or wherever you like (you don't need a model to access single DB values, if you have a static query, where only the filter changes depending on your QLineEdit input).

      https://doc.qt.io/qt-5/sql-sqlstatements.html#executing-a-query


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • K Offline
        K Offline
        KingslyEn
        wrote on last edited by
        #3

        I've connected function and have QLineEdit input without pushbutton action,
        But I don't know how Display the result of query in textBox?

        And thanks for your answer 😊😉

        Pl45m4P 1 Reply Last reply
        0
        • K KingslyEn

          I've connected function and have QLineEdit input without pushbutton action,
          But I don't know how Display the result of query in textBox?

          And thanks for your answer 😊😉

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @KingslyEn

          Just take the QString and set it as text to your QTextEdit or QLineEdit with insertPlainText(QString)/ setText(QString). You can build a QStringList first or you can concatenate all the results you get from your query to display all results. QSqlQuery returns the records / db results one by one, so you have to iterate through your results, if your query returns multiple rows or columns.
          https://doc.qt.io/qt-5/sql-sqlstatements.html#navigating-the-result-set


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          1
          • K Offline
            K Offline
            KingslyEn
            wrote on last edited by
            #5

            Thanks a lot again, It's executed and works fine,
            :)

            Pablo J. RoginaP 1 Reply Last reply
            1
            • K KingslyEn

              Thanks a lot again, It's executed and works fine,
              :)

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @KingslyEn said in Display data real time in QT c++ from db:

              and works fine

              so could it be possible for you to mark this post as solved?

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              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