Qt-interest Archive, January 2007
creating data aware widgets:help needed
Message 1 in thread
Any suggestions on how to fix this will be greatly appreciated.
I am trying a very simple piece of code i got from the documentation but i am not able to see the data from my sql table, in the widgets that are mapped. The code is as follows: QSqlTableModel *model = new QSqlTableModel(this);model->setTable("user_info");QDataWidgetMapper *mapper = new QDataWidgetMapper();mapper->setModel(model);mapper->addMapping(comboBox, 0);mapper->addMapping(lineEdit_2, 1);mapper->addMapping(lineEdit_3, 2);mapper->addMapping(lineEdit_4, 3);mapper->addMapping(lineEdit_5, 4);connect(pushButton,SIGNAL(clicked()),mapper,SLOT(toNext())); I created a form with the widgets above (lineEdit, combobox ect) and created a class which inherits the form class, what i have above is an extract form the constructor for my derived class. But when the program runs i see nothing in the widgets. I tested the mapping using int QDataWidgetMapper::mappedSection ( QWidget * widget ) const and used a qmessage box to output the return value that indicates that the widget was mapped to a particular section, and the mapping seem to be successful, but there is nothing being displayed in the widgets. I saw in the archive where someone else was having problems with it but no one responded to him. But i see others saying they are able to use it, if you can give me an example of how to make it work that would be great. Thanks in advance.
_________________________________________________________________
Get into the holiday spirit, chat with Santa on Messenger.
http://imagine-windowslive.com/minisites/santabot/default.aspx?locale=en-us
Message 2 in thread
Friday 19 January 2007 00:52 keith burke wrote:
> Any suggestions on how to fix this will be greatly appreciated.
I have two suggestions for you:
1) Did you connect to the database? It might be obvious to you, but you don't
mention that this was done. You need to set up the connection with the
QSqlDatabase class before attempting to use it.
2) Try putting your QSqlTableModel directly in a QTableView. This will show
you if you get anything from the database. Right now, there's no way to see
if your problem is in the use of the database or the mapper.
Try those and write a new mail if you still have problems with it.
Bo Thorsen.
> I am trying a very simple piece of code i got from the documentation but i
> am not able to see the data from my sql table, in the widgets that are
> mapped. The code is as follows: QSqlTableModel *model = new
> QSqlTableModel(this);model->setTable("user_info");QDataWidgetMapper *mapper
> = new
> QDataWidgetMapper();mapper->setModel(model);mapper->addMapping(comboBox,
> 0);mapper->addMapping(lineEdit_2, 1);mapper->addMapping(lineEdit_3,
> 2);mapper->addMapping(lineEdit_4, 3);mapper->addMapping(lineEdit_5,
> 4);connect(pushButton,SIGNAL(clicked()),mapper,SLOT(toNext())); I created a
> form with the widgets above (lineEdit, combobox ect) and created a class
> which inherits the form class, what i have above is an extract form the
> constructor for my derived class. But when the program runs i see nothing
> in the widgets. I tested the mapping using int
> QDataWidgetMapper::mappedSection ( QWidget * widget ) const and used a
> qmessage box to output the return value that indicates that the widget was
> mapped to a particular section, and the mapping seem to be successful, but
> there is nothing being displayed in the widgets. I saw in the archive where
> someone else was having problems with it but no one responded to him. But i
> see others saying they are able to use it, if you can give me an example of
> how to make it work that would be great. Thanks in advance.
> _________________________________________________________________
> Get into the holiday spirit, chat with Santa on Messenger.
> http://imagine-windowslive.com/minisites/santabot/default.aspx?locale=en-us
--
[ signature omitted ]
Message 3 in thread
<html><div style='background-color:'><DIV class=RTE>
<P> </P>
<P>I am able to connect to the database. I even have a QMessageBox to tell me if i didn't, and i am able to view the data using the QTableView and the QSqlTableModle together. So i am pretty sure its not my connection; should have metioned that i checked that.</P>
<P> I was just thiking of creating a custom delegate to read and write data between the widgets and the modle but that would be re-inventing the wheel as the mapper has a default delegate to handle that(running out of ideas). Plus i'm not using custom widgets.</P>
<P>Even tried creating an editor that takes a QVariant type. I added this editor(that inherited QLineEdit) to my form and tried mapping it to a section of the model (just to see if the default delegate was having problems with transfering the particular data types from the database to the widgets). But then that didn't work and i knew it wouldn't have because i am using things like 'char' and 'varchar' and 'int' as the types for the data in the database, which should easily be displayed in a QLineEdit or spinbox by the delegate. But they were stuff to try.</P>
<P>Any suggestions you can give will be appreciated.<FONT face="Times New Roman, Times, Serif" size=2><BR></P></FONT></DIV>
<DIV></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #a0c6e5 2px solid; MARGIN-RIGHT: 0px"><FONT style="FONT-SIZE: 11px; FONT-FAMILY: tahoma,sans-serif">
<HR color=#a0c6e5 SIZE=1>
<DIV></DIV>From: <I>Bo Thorsen <bo@xxxxxxxxxxxxxxxxxxxxx></I><BR>To: <I>qt-interest@xxxxxxxxxxxxx</I><BR>Subject: <I>Re: creating data aware widgets:help needed</I><BR>Date: <I>Fri, 19 Jan 2007 08:40:18 +0100</I><BR>>Friday 19 January 2007 00:52 keith burke wrote:<BR>> > Any suggestions on how to fix this will be greatly appreciated.<BR>><BR>>I have two suggestions for you:<BR>><BR>>1) Did you connect to the database? It might be obvious to you, but you don't<BR>>mention that this was done. You need to set up the connection with the<BR>>QSqlDatabase class before attempting to use it.<BR>><BR>>2) Try putting your QSqlTableModel directly in a QTableView. This will show<BR>>you if you get anything from the database. Right now, there's no way to see<BR>>if your problem is in the use of the database or
the mapper.<BR>><BR>>Try those and write a new mail if you still have problems with it.<BR>><BR>>Bo Thorsen.<BR>><BR>> > I am trying a very simple piece of code i got from the documentation but i<BR>> > am not able to see the data from my sql table, in the widgets that are<BR>> > mapped. The code is as follows: QSqlTableModel *model = new<BR>> > QSqlTableModel(this);model->setTable("user_info");QDataWidgetMapper *mapper<BR>> > = new<BR>> > QDataWidgetMapper();mapper->setModel(model);mapper->addMapping(comboBox,<BR>> > 0);mapper->addMapping(lineEdit_2, 1);mapper->addMapping(lineEdit_3,<BR>> > 2);mapper->addMapping(lineEdit_4, 3);mapper->addMapping(lineEdit_5,<BR>> > 4);connect(pushButton,SIGNAL(clicked()),mapper,SLOT(toNext())); I created a<BR>> > form with the widgets above (lineEdit, combobox
ect) and created a class<BR>> > which inherits the form class, what i have above is an extract form the<BR>> > constructor for my derived class. But when the program runs i see nothing<BR>> > in the widgets. I tested the mapping using int<BR>> > QDataWidgetMapper::mappedSection ( QWidget * widget ) const and used a<BR>> > qmessage box to output the return value that indicates that the widget was<BR>> > mapped to a particular section, and the mapping seem to be successful, but<BR>> > there is nothing being displayed in the widgets. I saw in the archive where<BR>> > someone else was having problems with it but no one responded to him. But i<BR>> > see others saying they are able to use it, if you can give me an example of<BR>> > how to make it work that would be great. Thanks in advance.<BR>> >
_________________________________________________________________<BR>> > Get into the holiday spirit, chat with Santa on Messenger.<BR>> > http://imagine-windowslive.com/minisites/santabot/default.aspx?locale=en-us<BR>><BR>>--<BR>><BR>>Thorsen Consulting ApS - Qt consulting services<BR>>http://www.thorsen-consulting.dk<BR>><BR>>--<BR>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.<BR>>List archive and information: http://lists.trolltech.com/qt-interest/<BR>><BR></FONT></BLOCKQUOTE></div><br clear=all><hr> <a href="http://g.msn.com/8HMBENUS/2740??PS=47575" target="_top">FREE online classifieds from Windows Live Expo ? buy and sell with people you know</a> </html>
--
[ signature omitted ]