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 triggereditingFinished
you need to press enter or leave the textEdit to make it lose the input focus.
SotextChanged
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 yourQLineEdit
it will producef 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
-
Just take the
QString
and set it as text to yourQTextEdit
orQLineEdit
withinsertPlainText(QString)
/setText(QString)
. You can build aQStringList
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 -
@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?