Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: How to transfer data entered in a QWizard to other classes?

  1. #1
    Join Date
    Feb 2009
    Location
    Portugal
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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
    Qt Code:
    1. MyWizard wiz;
    2. wiz.exec()
    3. wiz.getMyFancyData(); // where you have to implement these function in your wizard class...
    To copy to clipboard, switch view to plain text mode 

    Lykurg

  3. #3
    Join Date
    Feb 2009
    Location
    Portugal
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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

    Qt Code:
    1. QString sessionName = field("session.name").toString();
    To copy to clipboard, switch view to plain text mode 

    which is ok. My problem is that i want to recover data from a QTableWidget! Any ideas on how to do this?


    thanks for your help,
    david

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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.

  5. #5
    Join Date
    Feb 2009
    Location
    Portugal
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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...


    This is what i have in my startwizard.h
    Qt Code:
    1. class startWizard : public QWizard
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. enum{Page_Intro, Page_New, Page_Load, Page_Configs, Page_LoadDetails, Page_NewDetails};
    7. startWizard(QWidget *parent = 0);
    8.  
    9. void accept();
    10.  
    11. };
    12.  
    13. (...)
    14.  
    15. class configsPage : public QWizardPage
    16. {
    17. Q_OBJECT
    18.  
    19. public:
    20. configsPage(QWidget *parent = 0);
    21. int nextId();
    22.  
    23. private:
    24. (...)
    25. QTableWidget *tableDisplay;
    26.  
    27. (...)
    28. };
    To copy to clipboard, switch view to plain text mode 

    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...


    thanks a lot for the help,
    david

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to transfer data entered in a QWizard to other classes?

    Qt Code:
    1. class startWizard : public QWizard
    2. {
    3. Q_OBJECT
    4. public:
    5. enum{Page_Intro, Page_New, Page_Load, Page_Configs, Page_LoadDetails, Page_NewDetails};
    6. startWizard(QWidget *parent = 0);
    7. void accept();
    8. private:
    9. configsPage *m_configsPage;
    10. };
    11.  
    12. startWizard::startWizard(QWidget *parent) : QWizard(parent) {
    13. //...
    14. m_configsPage = new configsPage(this);
    15. addPage(m_configsPage);
    16. //...
    17. }
    18.  
    19. void startWizard::accept() {
    20. //...
    21. m_configsPage->table() //<- here's your pointer...
    22. //...
    23. }
    24. (...)
    25.  
    26. class configsPage : public QWizardPage
    27. {
    28. Q_OBJECT
    29.  
    30. public:
    31. configsPage(QWidget *parent = 0);
    32. int nextId();
    33. const QTableWidget* table() const {return tableDisplay;}
    34.  
    35. private:
    36. (...)
    37. QTableWidget *tableDisplay;
    38.  
    39. (...)
    40. };
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to Lykurg for this useful post:

    dcopeto (27th March 2009)

  9. #8
    Join Date
    Feb 2009
    Location
    Portugal
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Talking Re: How to transfer data entered in a QWizard to other classes? (SOLVED)

    THANK YOU!

    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

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #10
    Join Date
    Feb 2009
    Location
    Portugal
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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...


    thanks,
    david

  12. #11
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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(..) ?

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to transfer data entered in a QWizard to other classes?

    You can pass anything that will fit into QVariant.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #13
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #15
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to transfer data entered in a QWizard to other classes?

    Quote Originally Posted by BillGates View Post
    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.

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #17
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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...

    }

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to transfer data entered in a QWizard to other classes?

    Quote Originally Posted by BillGates View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #19
    Join Date
    Feb 2010
    Posts
    24
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 ?

  21. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Default Item View classes and returning data from model
    By xerionn in forum Qt Programming
    Replies: 8
    Last Post: 23rd April 2009, 19:50
  2. Item View classes and returning data !
    By xerionn in forum Newbie
    Replies: 3
    Last Post: 16th January 2009, 08:52
  3. Qcj Data classes initial release
    By croftj in forum Qt-based Software
    Replies: 0
    Last Post: 1st May 2007, 02:51
  4. Replies: 1
    Last Post: 9th March 2007, 21:07
  5. Record update windowd entered data saving
    By MarkoSan in forum Qt Programming
    Replies: 56
    Last Post: 18th January 2006, 18:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.