Important: Please read the Qt Code of Conduct -

Save user input

  • Hi!

    I'm a student taking a basic course in C++ programming. Currently, I'm doing a project in which a graphical user interface must be used. The teachers recommended QT for my type of here I am.

    Anyway, I'm using a QT GUI application and have a hard time figuring out how to save user input.

    !'s how it looks)!

    Currently I'm using this function to save the user input, but when I display the information all I get is the information set in the default constructor.

    @void addBasicCompetitionInformation::on_buttonBox_accepted()

    Have tried to google the problem, and understand that text() isn't right to use...but I'm not sure which solution is the simplest one. Does anyone have any suggestions?

    If you need more code feel free to point that out. :)

  • If your whole application is based on Qt, you probably don't need the conversions back and forth the StdString. QString will do just fine, and is by many regarded as better than stdString.

    It is not very clear what you want to achieve exactly. What do you mean by "saving" in this context? Saving to disk? If so, what kind of format are you looking for? There are many ways to do such a thing, but in order to recommend a good one, we have to know your targets. Also, this being homework, we'd like to ensure you learn from the excersise of course :-)

    So: first step in this assignment:

    clearly define your requirements. What do you need to do exactly?

    what part of that requirement do you require help with?

  • The reason I need a a StdString is that practically the whole application is written in Visual Studio already. Thus, the main part of the project is implemented. Now I just need to connect what I've got to QT. :)

    So, what I'm trying to accomplish in this particular case is to store the data entered in the line widgets by the user in variables belonging to a C++ class (called Competition). In order to do so I use member functions of that class (set-functions). A Competition object (comp1) is used to reach those member functions. The data (if entered) shall be stored once the user presses the "OK" button.

  • OK, that clears it up a little.
    In that case, your code actually looks good. Using ::text() is save, there are no issues with that.

  • Maybe you are looking at the wrong Competition object?

  • Oh man that's awkward...yes I am! :) Thank you both for your responses!

  • Moderators

    Something completely different: Are you using layouts in your UI? If not: You should:-)

    I am asking since that screenshot looks like you just positioned elements on a widget (which seems how you do it in windows MFC from the little I have seen of that;-).

  • Hello,

    I am kind of trying to do the same.
    I have created a calendar widget and I need to store the user entered data when a button ( for instance "generate") is clicked,into a text file or xml.
    How do I do it ?
    I have created a button. But I am not sure as to how to go about saving user entered data into a file explicitly and where is the data stored.. how do I access it to put it in a file.
    Can somebody please help me ?

    Thanks a lot in advance,

Log in to reply