[Qt-interest] QSqlQuery and QSqlTableModel show empty
Israel Brewster
israel at frontierflying.com
Mon May 18 18:22:39 CEST 2009
On May 15, 2009, at 2:44 AM, Jon Flowers wrote:
> Well solved the QSqlTableModel issue, bad database username/password
> combo. But still can not successfully get a QSqlQuery to execute
>
> QSqlQuery myQuery(“select * from projects”);
> myQuery.exec(); <- returns false every time even when the
> tablemodel gets filled with data.
>
> Any ideas?
QMessageBox::critical(NULL,"Database",myQuery.lastError().text());
That should give you a dialog showing what error (if any) is occurring
with your SQL query. I would think that if exec() is returning false,
this should be populated. Hopefully, that will give you a good
starting point for figuring out how to fix it.
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
>
> Thanks
> Jon
>
>
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com
> ] On Behalf Of Jon Flowers
> Sent: Friday, May 15, 2009 11:18 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] QSqlQuery and QSqlTableModel show empty
>
> Need some help with the Sql Modules.
>
> I have read some of the books out there and looked at the examples.
> I have a postgres database up and running with a table and one row
> in it. I can create a connection to this database from main.cpp, but
> I would like to use the QSqlTableModel on the mainwindow.cpp class.
> I have queried the connection and it says it is active, but when I
> follow example to show the table on the gui I get the columns in the
> header, but no data. I have tried to get a QSqlQuery to just test
> things and it also returns no data.
>
> …
>
> projModel.setTable(“tablename”);
>
> projModel.select();
>
> ui.tbvProjects->setModel(&projModel);
>
> ui.tbcProjects->show();
>
> No data comes back but the headers are correct. So that leads me to
> believe I do have a connection but the query is not returning any
> data. And to answer the obvious, I have verified the table contains
> data by pgAdmin from a different machine and also via psql on the
> database server (local dev machine).
>
> Any ideas, pointers and general comments welcome….
>
> Thanks
>
> Jon
>
> This email and any files contained therein is confidential and may
> contain privileged information. If you are not the named
> addressee(s) or you have otherwise received this in error, you
> should not distribute or copy this e-mail or use any of its content
> for any purpose. Please notify the sender immediately by e-mail if
> you have received this e-mail in error and delete it from your system
> This email and any files contained therein is confidential and may
> contain privileged information. If you are not the named
> addressee(s) or you have otherwise received this in error, you
> should not distribute or copy this e-mail or use any of its content
> for any purpose. Please notify the sender immediately by e-mail if
> you have received this e-mail in error and delete it from your
> system _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090518/69d96bec/attachment.html
More information about the Qt-interest-old
mailing list