How to transfer data entered in a QWizard to other classes?
Hi!
I'm using a QWizard to get some user configurations at the beggining of my program but i can't seem to find a way to fill in my database class with the data the user enters in the wizard pages! How can this be done?
thanks a lot for the help,
david
Re: How to transfer data entered in a QWizard to other classes?
Hi,
have a look at the docs, there you can find your questions answered: Class Wizard Example. Especially "void ClassWizard::accept()".
Or in your code is somewhere
Code:
MyWizard wiz;
wiz.exec()
wiz.getMyFancyData(); // where you have to implement these function in your wizard class...
Lykurg
Re: How to transfer data entered in a QWizard to other classes?
Thanks for the reply :)
Yeah in the meantime i found that too and my problem changed:
From what i understood, one recovers the data using something like
Code:
QString sessionName
= field
("session.name").
toString();
which is ok. My problem is that i want to recover data from a QTableWidget!:confused: Any ideas on how to do this?
thanks for your help,
david
Re: How to transfer data entered in a QWizard to other classes?
The "field" way is only one possibility. Since the QWizard is a normal class you can simply add a private member which points to the table. Use this pointer in the "save" function to get the data.
Re: How to transfer data entered in a QWizard to other classes?
Maybe i didn't give you enough details because i'm having trouble finding out to do that...:crying:
This is what i have in my startwizard.h
Code:
class startWizard : public QWizard
{
Q_OBJECT
public:
enum{Page_Intro, Page_New, Page_Load, Page_Configs, Page_LoadDetails, Page_NewDetails};
void accept();
};
(...)
class configsPage : public QWizardPage
{
Q_OBJECT
public:
int nextId();
private:
(...)
(...)
};
In the ConfigsPage of the wizard i create the table for the user to see what he's adding/configuring and then i want to be able to recover the data he just entered to my database object in the main application.
In your previous reply you meant placing a QTableWidget pointer in the startWizard class, pointing to the table that gets the stuff in ConfigsPage class? even that i'm having trouble with...
I still don't see how can i go on from there? I mean to have access to the database I must make the wizard have access to the database somehow...:confused:
thanks a lot for the help,
david
Re: How to transfer data entered in a QWizard to other classes?
Move the table widget pointer to your QWizard subclass and then access the pointer when you want to retrieve the data.
Re: How to transfer data entered in a QWizard to other classes?
Code:
class startWizard : public QWizard
{
Q_OBJECT
public:
enum{Page_Intro, Page_New, Page_Load, Page_Configs, Page_LoadDetails, Page_NewDetails};
void accept();
private:
configsPage *m_configsPage;
};
startWizard
::startWizard(QWidget *parent
) : QWizard
(parent
) { //...
m_configsPage = new configsPage(this);
addPage(m_configsPage);
//...
}
void startWizard::accept() {
//...
m_configsPage->table() //<- here's your pointer...
//...
}
(...)
class configsPage : public QWizardPage
{
Q_OBJECT
public:
int nextId();
private:
(...)
(...)
};
Re: How to transfer data entered in a QWizard to other classes? (SOLVED)
THANK YOU!:D
That took care of my table access and now I have also managed to 'reach' the dataBase from the wizard by passing a pointer to the database to it!
thanks again,
david
Re: How to transfer data entered in a QWizard to other classes? (SOLVED)
You don't have to transfer pointers to the database (assuming you are using QSqlDatabase). You can always retrieve the connection by calling it by name. See docs of QSqlDatabase.
Re: How to transfer data entered in a QWizard to other classes?
Hey! thanks for the suggestion! I'm not using sqlDatabase, I'm using my own storing class, because it's not a lot of stuff, anyway can you tell me when does it 'payoff' to use a sql database instead of a custom class? I'm not really into it so it's probable that I'm writing garbage right this moment... :o
thanks,
david
Re: How to transfer data entered in a QWizard to other classes?
hi
maybe i didnt understand very well the method that Lykurg wrote in code, but, will other Pages of the wizard be able to access m_configsPage->table() ?
Is it possible to pass objects instead of int/Qstrings using ::field() and registerField(..) ?
Re: How to transfer data entered in a QWizard to other classes?
You can pass anything that will fit into QVariant.
Re: How to transfer data entered in a QWizard to other classes?
Thanks for reply wysota !
Im sorry to ask, but is there any example somewhere ? I am a noob.
I searched on the net and even here but all I could find were widgets with properties that were int or string.
As I understand it it must be something like :
registerField("name", myWidget, "myProperty", SIGNAL(selectionChanged()));
so i conclude that i must declare my own widget and my own propery. Is this correct ?
My purpose is to make variables like a QList accessible to any/all wizardPage subclass.
Re: How to transfer data entered in a QWizard to other classes?
A QList of what? That's a template class, you know... And while you are at it, what is the reason for doing that? You can always expose the list using your wizard class's public interface.
Re: How to transfer data entered in a QWizard to other classes?
yes, i know its a template, pardon me, a QList<QString> . I didnt think it mattered much.
I dont understand what you mean by "your wizard class public interface" ? Maybe I am missing something?
Re: How to transfer data entered in a QWizard to other classes?
Quote:
Originally Posted by
BillGates
yes, i know its a template, pardon me, a QList<QString> . I didnt think it mattered much.
Well, it does, because QStringList is already registered to be used with QVariant.
Quote:
I dont understand what you mean by "your wizard class public interface" ? Maybe I am missing something?
I mean two methods in your wizard class's "public" section - one for setting the value and the other for getting it. Look at the code Lykurg has written, "table()" is the getter method and "setTable(QTableWidget*)" would be a setter method.
Still you didn't answer what you want to do with this all so maybe there are tons of better way to do what you want.
Re: How to transfer data entered in a QWizard to other classes?
I want for the QTableWidget *tableDisplay from the first QWizardPAGE to be accesible to the second, the third and so on Pages. So that i can use them for default values, exacty what the field() does.
The only problem is that I am not competent enough; I dont know how to pass my own variables through registerField().
If I have a QStringList created in Page1, i would like to access it in Page2 and Page3..
in void myPage2::initializePage() {
myObject list = field("some_field_registered_from_page1") <-- something like this...
}
Re: How to transfer data entered in a QWizard to other classes?
Quote:
Originally Posted by
BillGates
I want for the QTableWidget *tableDisplay from the first QWizardPAGE to be accesible to the second, the third and so on Pages. So that i can use them for default values, exacty what the field() does.
It's not what the field() does. To me it seams you need a model in your wizard. Then you can set this model to a QTableView (or QListView) in the first wizard page and also access the model from other pages. field() should represent a single value, not all possible values.
Re: How to transfer data entered in a QWizard to other classes?
Umh... so how would i access the model from the QWizard class from inside the Pages ? Pass it to their constructor ?
Re: How to transfer data entered in a QWizard to other classes?
You can do it any way you see fit. C++ allows for many solutions to this problem. For instance each page has a pointer to the wizard object it is part of.