An error occurred while accessing the database
Dear my friends... I move forward to getting to know more about qt in database application development. I tried to make a very simple database application qith QTable. I have made the database connection successfully. I found no error. If I click on "connect" it can connect successfully because the connection name move to the left hand column. The documentation in help menu said it is so. Compiled successfully. but if I run the compiled code, i found this error message as a prompt window comes: " An error occurred while accessing the database ". And the error message on the linux console where I executed "./book" are under below: " patrixlinux@patrix:~/arsip/proyek/qt/book> ./book QSqlCursor::setName: unable to build record, does 'author' exist? QSqlRecord::field: index out of range: 0 QSqlRecord::position: unable to find field forename QSqlRecord::field: index out of range: -1 QSqlRecord::field: index out of range: 1 QSqlRecord::position: unable to find field surname QSqlRecord::field: index out of range: -1 QSqlCursor::setName: unable to build record, does 'author' exist? patrixlinux@patrix:~/arsip/proyek/qt/book> " the author table really exists. should do choosing the database name as I do usually on PHP+MySQL ( mysql_select_db("192.168.23.21","patrix", "perjaka"); )? I have tested to connect to my mysql server with the same hostname, username and password and it's OK. I also can do select query. I did testing with mysql-client (mysql -h 192.168.23.21 -u patrix -p) Please tell me where my mistake. Thank you very much in advance. ps: Here is what I've done underbelow: patrixlinux@patrix:~/arsip/proyek/qt/book> ls book.db book.pro depanform.ui depanform.ui~ main.cpp patrixlinux@patrix:~/arsip/proyek/qt/book> qmake -o Makefile book.pro patrixlinux@patrix:~/arsip/proyek/qt/book> make /usr/lib/qt3/bin/uic depanform.ui -o .ui/depanform.h g++ -c -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/lib/qt3/mkspecs/default -I. -I/usr/include -I/usr/lib/qt3/include -I.ui/ -I. -I.moc/ -o .obj/main.o main.cpp /usr/lib/qt3/bin/uic depanform.ui -i depanform.h -o .ui/depanform.cpp g++ -c -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/lib/qt3/mkspecs/default -I. -I/usr/include -I/usr/lib/qt3/include -I.ui/ -I. -I.moc/ -o .obj/depanform.o .ui/depanform.cpp /usr/lib/qt3/bin/moc .ui/depanform.h -o .moc/moc_depanform.cpp g++ -c -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -fPIC -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/lib/qt3/mkspecs/default -I. -I/usr/include -I/usr/lib/qt3/include -I.ui/ -I. -I.moc/ -o .obj/moc_depanform.o .moc/moc_depanform.cpp g++ -o book .obj/main.o .obj/depanform.o .obj/moc_depanform.o -L/usr/lib/ -L/usr/lib/qt3/lib/ -L/usr/X11R6/lib/ -lqt -lXext -lX11 -lm patrixlinux@patrix:~/arsip/proyek/qt/book> ls Makefile book book.db book.pro depanform.ui depanform.ui~ main.cpp patrixlinux@patrix:~/arsip/proyek/qt/book> ./book QSqlCursor::setName: unable to build record, does 'author' exist? QSqlRecord::field: index out of range: 0 QSqlRecord::position: unable to find field forename QSqlRecord::field: index out of range: -1 QSqlRecord::field: index out of range: 1 QSqlRecord::position: unable to find field surname QSqlRecord::field: index out of range: -1 patrixlinux@patrix:~/arsip/proyek/qt/book> cat main.cpp #include <qapplication.h> #include "depanform.h" int main( int argc, char ** argv ) { QApplication a( argc, argv ); depanForm w; w.show(); a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); return a.exec(); } patrixlinux@patrix:~/arsip/proyek/qt/book> cat book.pro unix { UI_DIR = .ui MOC_DIR = .moc OBJECTS_DIR = .obj } TEMPLATE = app LANGUAGE = C++ CONFIG += qt warn_on release SOURCES += main.cpp FORMS = depanform.ui DBFILE = book.db patrixlinux@patrix:~/arsip/proyek/qt/book> cat depanform.ui <!DOCTYPE UI><UI version="3.3" stdsetdef="1"> <class>depanForm</class> <widget class="QDialog"> <property name="name"> <cstring>depanForm</cstring> </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>600</width> <height>480</height> </rect> </property> <property name="caption"> <string>Halaman depan</string> </property> <widget class="QDataTable"> <column> <property name="text"> <string>Forename</string> </property> <property name="field"> <string>forename</string> </property> </column> <column> <property name="text"> <string>Surname</string> </property> <property name="field"> <string>surname</string> </property> </column> <property name="name"> <cstring>dataTable1</cstring> </property> <property name="geometry"> <rect> <x>90</x> <y>20</y> <width>390</width> <height>220</height> </rect> </property> <property name="sorting"> <bool>true</bool> </property> <property name="confirmDelete"> <bool>true</bool> </property> <property name="database" stdset="0"> <stringlist> <string>(default)</string> <string>author</string> </stringlist> </property> </widget> </widget> <pixmapinproject/> <layoutdefaults spacing="6" margin="11"/> </UI> patrixlinux@patrix:~/arsip/proyek/qt/book> cat book.db <!DOCTYPE DB><DB version="1.0"> <connection> <property name="name"> <string>(default)</string> </property> <property name="driver"> <string>QMYSQL3</string> </property> <property name="database"> <string>book</string> </property> <property name="username"> <string>root</string> </property> <property name="hostname"> <string>192.168.23.21</string> </property> <property name="port"> <string>-1</string> </property> <table> <property name="name"> <string>author</string> </property> <field> <property name="name"> <string>id</string> </property> </field> <field> <property name="name"> <string>forename</string> </property> </field> <field> <property name="name"> <string>surname</string> </property> </field> </table> <table> <property name="name"> <string>book</string> </property> <field> <property name="name"> <string>id</string> </property> </field> <field> <property name="name"> <string>title</string> </property> </field> <field> <property name="name"> <string>price</string> </property> </field> <field> <property name="name"> <string>authorid</string> </property> </field> <field> <property name="name"> <string>notes</string> </property> </field> </table> <table> <property name="name"> <string>sequence</string> </property> <field> <property name="name"> <string>tablename</string> </property> </field> <field> <property name="name"> <string>sequence</string> </property> </field> </table> </connection> </DB> patrixlinux@patrix:~/arsip/proyek/qt/book> __________________________________ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/
On Tuesday 25 May 2004 13:40, Prabu Subroto wrote:
Dear my friends...
I move forward to getting to know more about qt in database application development.
I tried to make a very simple database application qith QTable.
I have made the database connection successfully. I found no error. If I click on "connect" it can connect successfully because the connection name move to the left hand column. The documentation in help menu said it is so.
You need to include code in main.cpp to connect to the database at run-time. In designer, press F1 which should bring up the Qt documentation. Then select Home, Modules, SQL for information on how to use databases, including sample connect code. Cheers, TonyB
participants (2)
-
Prabu Subroto
-
Tony Bloomfield