Sunday, July 6th 2008, 4:43pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, April 25th 2008, 7:22am

DataBrowser problem.

Hi ,
I am new to Qt tool. I am using Qt4.3.3 with VS2005.I have a problem. I have created a .Ui Form in which i have a few Radio Buttons and Group box's. When i select the required Radio Button from each Group Box and click OK finally, i wanted to store the selected Radio Button Label and its Group Box Title into a Sqlite data base which i have to retrive and display in a Table on a click of a Button. I tried many examples and searched the Net but i din't get any solution. How should i go about doing this. Pls help me out. Any example similar to this pls link it .


Advance thank's to all..

Regards,
Tavi.

This post has been edited 1 times, last edit by "tavi" (Apr 25th 2008, 7:35am)

  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

2

Friday, April 25th 2008, 10:17am

RE: DataBrowser problem.

Provided all QRadioButton (s) have QGroupBox as parent (or could be analyzed).

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
// find all QRadioButton's
QList<QRadioButton*> rButtons = this->findChildren<QRadioButton*>();
//
int i;
for (i = 0; i < rButtons.count(); ++i)
{
    // find selected
    if( rButtons.at(i)->isChecked())
    {
        // analyze rButtons.at(i) and it's parent.
        // write required properties anywhere you want.
    }
}


http://doc.trolltech.com/4.3/qobject.html#findChildren
http://doc.trolltech.com/4.3/qobject.html#parent

The code is just suggestion. No warranty ;)
Fighting fire with fire.
  • Go to the top of the page

3

Saturday, April 26th 2008, 6:48am

RE: DataBrowser problem.

Hi Messenger,
Thank's for reply.I tried what ever you said,still Baffled.So could you send any similar example program.
Please help me ...


Regards,
Tavi.
  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

4

Saturday, April 26th 2008, 9:53am

RE: DataBrowser problem.

You can hardcode. You know that such and such QRadioButton is in particular QGroupBox.

There is little example (compiled & tested with g++ 4.2.3, Qt 4.3.4, linux). If you want something else then make example Qt project (with comments) and attach.
Messenger has attached the following file:
  • rbtns.zip (2.67 kB - 14 times downloaded - Last download: Jul 4th 2008, 5:06am)
Fighting fire with fire.
  • Go to the top of the page

5

Monday, April 28th 2008, 10:39am

RE: DataBrowser problem.

Hi Messenger,
Thank's for reply.I tried what ever you said.I got it output
(All are saved into notepad),But i want to know .ui form data insert into Database using Sqlite.
How to create Table dynmically and store to particular table.
How to Retrive Data from Database.
tavi has attached the following file:
  • sample.rar (2.79 MB - 16 times downloaded - Last download: Jun 2nd 2008, 9:45pm)
  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

6

Monday, April 28th 2008, 12:08pm

RE: DataBrowser problem.

There is working (I thnk) sample. click "save" to save values, click 'cancel" to get info. I was too lazy to modify ui and... Well if something not right. Ask.
Messenger has attached the following file:
  • sample.zip (4.89 kB - 11 times downloaded - Last download: May 31st 2008, 1:51am)
Fighting fire with fire.
  • Go to the top of the page

7

Monday, April 28th 2008, 2:08pm

RE: DataBrowser problem.

Hey Thanks a millon for the Program you have posted. But i get 336 errors when i debug the program. What are the changes i need to do in the Ui form. The program looks very fine but i don't know why i get so many errors. What do i need to do i have intialize in the Ui form.

Thanks Again Messenger.
  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

8

Monday, April 28th 2008, 2:25pm

RE: DataBrowser problem.

What are the errors (show them)? How can I tell if no info. Look at the errors try to figure out what they mean and modify sources.
The sample works on Qt 4.3.4, g++ 4.2.3, linux. The sample works or not at all?
Fighting fire with fire.
  • Go to the top of the page

9

Monday, April 28th 2008, 2:51pm

OutPut error

Hi messenger i have attached the error log. I checked the code every thing is fine. But i am not able to figure out from where the error occurs. What should i change in the .UI form.

Thank You
tavi has attached the following file:
  • Output-Build.txt (27.33 kB - 17 times downloaded - Last download: May 24th 2008, 4:27am)
  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

10

Monday, April 28th 2008, 2:59pm

RE: OutPut error

memory (Memory) file must NOT be included in build (it is sqlite database file) and never appear anywhere in project files. Remove Memory file from project (and anywhere). Rebuild and if any error - post it here.


[Edit]
Ok just downloaded it on xp.
>qmake
>nmake

Yep the same errors :evil:
Deleted Memory file.
>nmake
Fine.
Rename sqlite database file (setDatabaseName) something else. Apparently it's name conflicts with some standard cpp file name.
Fighting fire with fire.

This post has been edited 3 times, last edit by "Messenger" (Apr 28th 2008, 3:25pm)

  • Go to the top of the page

11

Tuesday, April 29th 2008, 9:47am

Table View.

Hi Messenger,
Thank's alot.The program worked fine.After i did the changes you told me, but i wanted the output in TableView.Right now the retrived data is displayed in a message box. I will be selecting lots of data so i wanted the retrived data to be displayed in Table view.

Thank's Again
:)
  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

12

Tuesday, April 29th 2008, 11:17am

RE: Table View.

Well here is example. Other way is to use QTableWidget and insert items by hand (iterating QSqlQuery like I have done to show info).
Messenger has attached the following file:
  • sample2.zip (4.74 kB - 10 times downloaded - Last download: May 31st 2008, 1:50am)
Fighting fire with fire.
  • Go to the top of the page

13

Wednesday, April 30th 2008, 8:43am

RE: Table View.

Hi,
Thank you Messenger.I got the Example.I dont want that way output.
I want the output this way, when i selected all buttons and groupboxs after that click ok Button then save in to database and close Button clicks iwant to display Data in Table popup window(Not on Message Box).

Thank you...



Regards,
Tavi.
  • Go to the top of the page

14

Friday, May 2nd 2008, 9:09am

form load

Hi messenger,
I am able to save the form fields into the database. Once i am done with this i close that particular form. But when i reopen the form again how do i set the radio buttons which were selected last time from the database automatically. I just wanted to keep the radio buttons status the same so that the user don't have to reselect all the radio buttons again when he opens the same form again in tat particular session. And i can't enable the set checked option here because the user can select any set of radio button's every time he open's the application.

Thank You Messenger.
  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

15

Friday, May 2nd 2008, 10:03am

RE: form load

Query database. Get QRadioButton list. Traverse & examine parent of QRadioButton. setChecked(tru) if conditions are met.

[Edit]
Maybe better get QGroupBox list and examine rather then QRadioButton list. Might be faster. In any case QRadioButton list will be bigger and if there are large number of QRadioButton...
Get QGroupBox list, find one, get list of children, find one and setChecked.

For example like this (modified last example).
Messenger has attached the following file:
  • example3.zip (5.06 kB - 11 times downloaded - Last download: Jun 20th 2008, 12:05am)
Fighting fire with fire.

This post has been edited 1 times, last edit by "Messenger" (May 2nd 2008, 10:13am)

  • Go to the top of the page

16

Friday, May 2nd 2008, 1:06pm

DataBrowser problem.

Hi messenger,
Thank's alot.The Example program is working fine.I got it solution.If i get any problem i get back to you.
Thankyou......Very much.....



Regards,
Tavi.
  • Go to the top of the page

17

Monday, May 5th 2008, 9:46am

RE: DataBrowser problem.

Hi messenger,

I have small problem.Please solve me.Example3 is working fine..When i added 18 no of groupboxes and each have three radioButtons instead of 3 groupboxes and 2 radio Buttons.I dont get Table view in order.Can you tell me How it Solve this..


I tried this way.

void sample::on_cancelpushButton_clicked()
{
QTableView *tv;
tv = new QTableView();
QSqlQueryModel *model = new QSqlQueryModel(tv);
model->setQuery("SELECT * FROM Temp ");
tv->setModel(model);
tv->show();
this->close();
}

Instead of underline code i write this way:

model->setQuery("SELECT * FROM Temp ORDER BY ChannelID");

Is it correct? I am not getting any error.output is same,no change.


Thank you messenger,


Regards,
Tavi.

This post has been edited 1 times, last edit by "tavi" (May 5th 2008, 9:46am)

  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

18

Monday, May 5th 2008, 11:00am

RE: DataBrowser problem.

Yes this is correct. But remember that there is two setQuery (one in on_cancelpushButton_clicked (cancel button) slot other in on_m_pbShow_clicked (show button) slot).
When you click cancel button - do you get correct table?
I've added up to 18 QGroupBox and output is correct after query "SELECT * FROM Temp ORDER BY ChannelID".
Messenger has attached the following file:
Fighting fire with fire.
  • Go to the top of the page

19

Monday, May 5th 2008, 12:29pm

RE: DataBrowser problem.

Hi messenger ,
you are given different names.so you get order.I am giving names same string for all ,At end of the word i gave a number in sequence.That time i am getting output randomly stored.I want output in sequential order.Can you tell me How...Please..
I attached my output.


And one more doubt is there any possibility for Editing the database through command prompt(like oracle.Mysql)?...

Thanking you...



Regards,
Tavi.
tavi has attached the following file:
  • output.bmp (515.83 kB - 9 times downloaded - Last download: May 31st 2008, 1:50am)

This post has been edited 1 times, last edit by "tavi" (May 5th 2008, 12:34pm)

  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

20

Monday, May 5th 2008, 2:39pm

RE: DataBrowser problem.

Yes, but your table is sorted good. That is
xxx 1
11
171
18
191
2
22
23333
28
3
333
3

Last upper case letter goes before first lower case (Wa). Etc.
See sqlite functions (http://www.sqlite.org/lang_corefunc.html) to make sort work your way.
Try something like.
"select * from Temp order by substr(ChannelID, 19, 10)"

also see lower, upper functions.

[edit]
On the other hand you can use QSortFilterProxyModel. Imho it gives more flexibility.
http://doc.trolltech.com/4.3/qsortfilterproxymodel.html
As I have understood you only need to reimplement lessThan function in derived class.

Other sql example
"SELECT * FROM Temp ORDER BY CAST ( substr(TypeofSensor, 13, 5) AS INTEGER)"
Though I found it unsatisfactory. Other values are unsorted. Maybe in this case it will be ok.
Messenger has attached the following file:
  • sort_sqlite_DD.png (207.75 kB - 64 times downloaded - Last download: Jun 1st 2008, 7:16am)
Fighting fire with fire.

This post has been edited 3 times, last edit by "Messenger" (May 5th 2008, 3:16pm)

  • Go to the top of the page

Rate this thread