Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Display data real time in QT c++ from db



  • 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



  • @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



  • 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 😊😉



  • @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



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



  • @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?


Log in to reply