Unsolved how to display data in lineedit from database
-
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
-
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 ? -
model = new QSqlTableModel(this, db);
model->setTable("Student");QSqlQuery query; query.prepare("select FirstName from Student"); query.exec();
this is my code
-
@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...
-
@jslum sir thank you
but it does not display all the data during form loading time -
@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? -
@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 -
@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 taskthat 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
-
@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 -
Hi,
What about QDataWidgetMapper ?