Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

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>&nbsp;</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>&nbsp;I was just thiking of creating a custom&nbsp;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&nbsp;data types from the database&nbsp;to the widgets). But then that didn't work and i knew it wouldn't have because&nbsp;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:&nbsp;&nbsp;<I>Bo Thorsen &lt;bo@xxxxxxxxxxxxxxxxxxxxx&gt;</I><BR>To:&nbsp;&nbsp;<I>qt-interest@xxxxxxxxxxxxx</I><BR>Subject:&nbsp;&nbsp;<I>Re: creating data aware widgets:help needed</I><BR>Date:&nbsp;&nbsp;<I>Fri, 19 Jan 2007 08:40:18 +0100</I><BR>&gt;Friday 19 January 2007 00:52 keith burke wrote:<BR>&gt; &gt; Any suggestions on how to fix this will be greatly appreciated.<BR>&gt;<BR>&gt;I have two suggestions for you:<BR>&gt;<BR>&gt;1) Did you connect to the database? It might be obvious to you, but you don't<BR>&gt;mention that this was done. You need to set up the connection with the<BR>&gt;QSqlDatabase class before attempting to use it.<BR>&gt;<BR>&gt;2) Try putting your QSqlTableModel directly in a QTableView. This will show<BR>&gt;you if you get anything from the database. Right now, there's no way to see<BR>&gt;if your problem is in the use of the database or 
the mapper.<BR>&gt;<BR>&gt;Try those and write a new mail if you still have problems with it.<BR>&gt;<BR>&gt;Bo Thorsen.<BR>&gt;<BR>&gt; &gt; I am trying a very simple piece of code i got from the documentation but i<BR>&gt; &gt; am not able to see the data from my sql table, in the widgets that are<BR>&gt; &gt; mapped. The code is as follows: QSqlTableModel *model = new<BR>&gt; &gt; QSqlTableModel(this);model-&gt;setTable("user_info");QDataWidgetMapper *mapper<BR>&gt; &gt; = new<BR>&gt; &gt; QDataWidgetMapper();mapper-&gt;setModel(model);mapper-&gt;addMapping(comboBox,<BR>&gt; &gt; 0);mapper-&gt;addMapping(lineEdit_2, 1);mapper-&gt;addMapping(lineEdit_3,<BR>&gt; &gt; 2);mapper-&gt;addMapping(lineEdit_4, 3);mapper-&gt;addMapping(lineEdit_5,<BR>&gt; &gt; 4);connect(pushButton,SIGNAL(clicked()),mapper,SLOT(toNext())); I created a<BR>&gt; &gt; form with the widgets above (lineEdit, combobox 
ect) and created a class<BR>&gt; &gt; which inherits the form class, what i have above is an extract form the<BR>&gt; &gt; constructor for my derived class. But when the program runs i see nothing<BR>&gt; &gt; in the widgets.&nbsp;&nbsp;I tested the mapping using int<BR>&gt; &gt; QDataWidgetMapper::mappedSection ( QWidget * widget ) const and used a<BR>&gt; &gt; qmessage box to output the return value that indicates that the widget was<BR>&gt; &gt; mapped to a particular section, and the mapping seem to be successful, but<BR>&gt; &gt; there is nothing being displayed in the widgets. I saw in the archive where<BR>&gt; &gt; someone else was having problems with it but no one responded to him. But i<BR>&gt; &gt; see others saying they are able to use it, if you can give me an example of<BR>&gt; &gt; how to make it work that would be great. Thanks in advance.<BR>&gt; &gt; 
_________________________________________________________________<BR>&gt; &gt; Get into the holiday spirit, chat with Santa on Messenger.<BR>&gt; &gt; http://imagine-windowslive.com/minisites/santabot/default.aspx?locale=en-us<BR>&gt;<BR>&gt;--<BR>&gt;<BR>&gt;Thorsen Consulting ApS - Qt consulting services<BR>&gt;http://www.thorsen-consulting.dk<BR>&gt;<BR>&gt;--<BR>&gt;To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.<BR>&gt;List archive and information: http://lists.trolltech.com/qt-interest/<BR>&gt;<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 ]