Results 1 to 20 of 24

Thread: Need to find a way to save user inputs.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Need to find a way to save user inputs.

    So I am making a kind of large app,which will be used by many people.
    In a seperate widget(class) I have put a tablewidget which is empty.
    User can use this tool to store data and save it.

    What I mean by "save", is that once some text is entered,it will be there next time the user opens the program.
    Then he might edit all the fields,add/remove colums/rows etc..

    The key part here is to make the fields saveable

    I have no idea how to do this..maybe there is some text file,so that I save all the data there,then read from it..or something else?

    Please help.

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

    Default Re: Need to find a way to save user inputs.

    And how does this differ from this thread?
    http://www.qtcentre.org/threads/4520...idget-for-this
    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.


  3. #3
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Need to find a way to save user inputs.

    Tables are different than lineedits.

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

    Default Re: Need to find a way to save user inputs.

    Are they...?
    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.


  5. #5
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Need to find a way to save user inputs.

    Well,for the Lineedit I do: set.setValue("text1", ui->le1->text()); then ui->le1->setText(set.value("text1").toString());
    While the Tablewidget doesn't have those functions( text(),setText() )..

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Need to find a way to save user inputs.

    QTableWidget has lines and columns that can hold QTableWidgetItems which items have setText member function.

  7. #7
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Need to find a way to save user inputs.

    Well,this is what I have so far:
    Qt Code:
    1. void Victims::save()
    2. {
    3. QSettings set("vic","tims");
    4. set.beginGroup("setting");
    5.  
    6. int grows = ui->tw->rowCount();
    7. int gcols = ui->tw->columnCount();
    8.  
    9. for(int i = 0; i < grows ;i++)
    10. {
    11.  
    12. for(int j = 0; j < gcols ;j++)
    13. {
    14. QTableWidgetItem* widgetItem = ui->tw->item(grows, gcols);
    15. tmp = widgetItem(i,j)->text(); //tmp is a string.
    16. if ( tmp.isEmpty() )
    17. break;
    18. }
    19. set.setValue("victims", tmp); //tmp will be the string that will be put into set.value(),correct?
    20. }
    21. set.endGroup();
    22. }
    To copy to clipboard, switch view to plain text mode 

    However it gives me an error: widgetItem cannot be used as a function :/
    Am I on the right way?

  8. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Need to find a way to save user inputs.

    widgetItem is already a pointer to the item at i,j index so use it without (i,j), just: widgetItem->setText("blabla");

    LE: don't forget to check for null, because, if i remember correctly, if the indexes are out-of range that item function returns null

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

    Default Re: Need to find a way to save user inputs.

    I suggest you come up with a universal solution that will work regardless of the item you want to store/restore. Provide classes or functions that will be called depending on the item/widget type you need to store and have some infrastructure that will call those classes/functions. You basically need something similar to QMainWindow::saveState() and QMainWindow::restoreState().
    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.


  10. #10
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Need to find a way to save user inputs.

    Right now I cannot put a simple table into settings,when you tell me to make a universal functionality..
    I suppose I'd better do it seperatly and if I have time I will think of what u said.

    So,my thought was to do this:
    Loop through the rowcount() and create as many arrays of string.
    Then use that nested loop(intthe code I pasted) and after each row,store the text into one array.
    Then in restore,I would re-loop(the table) to put the arrays as text..
    Is that ok?

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

    Default Re: Need to find a way to save user inputs.

    Quote Originally Posted by "BumbleBee" View Post
    Right now I cannot put a simple table into settings,when you tell me to make a universal functionality..
    You are considering the two as different problems whereas it is the same problem, it's just a matter of having a single solution doing all you want today and all you might want tomorrow or having a tightly coupled solution which works for what you want today but will require the same amount of work for each of the things you'll want tomorrow and the day after.
    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.


  12. #12
    Join Date
    Jan 2011
    Posts
    128
    Thanks
    2

    Default Re: Need to find a way to save user inputs.

    Hmm..I can't really come up with an idea that would work for any widget.
    Can you give me a hint?

Similar Threads

  1. How to implement functionalities of other devices/inputs in Qt
    By qt_user in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 9th October 2011, 10:32
  2. Save log file to "all user\application data\"
    By stella1016 in forum Qt Programming
    Replies: 3
    Last Post: 4th July 2011, 16:01
  3. Replies: 1
    Last Post: 13th June 2011, 13:06
  4. How to find the location of the user?
    By nikhilqt in forum Qt Programming
    Replies: 7
    Last Post: 14th December 2010, 18:22
  5. Restrict user from entering space in Save As File Name
    By jyoti kumar in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2007, 12:47

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.