Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [SOLVED]Remember Last LineEdit data
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED]Remember Last LineEdit data

Scheduled Pinned Locked Moved Qt Creator and other tools
15 Posts 3 Posters 10.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #5

    This the main.cpp file of my application ...Here idline is the pointer to QLineEdit taking input for Id
    @#include<QApplication>
    #include<websis.h>
    #include"gui.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    a.setApplicationName("Websis Desktop Application");
    a.setOrganizationName("LUG Manipal");
    a.setOrganizationDomain("rajatgupta431@gmail.com");
    qApp->addLibraryPath("C:/Qt/4.8.4/plugins/imageformats");

    QSettings *settings;
    settings = new QSettings;
    
    makegui gogoi;
    QVariant idvar;
    idvar.setValue(gogoi.idline->text());
    settings->setValue("Id",&idvar);
    gogoi.idline->setText(settings->value("id","not set").toString());
    
    return a.exec&#40;&#41;;
    

    }
    @
    Results are not as expected...Please look into it :)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #6

      You're not telling us what is "expected", so it is hard to judge where your code deviates from your plan

      Just use a QSettings object on the stack (line 14 & 15)

      What is makegui gogoi; doing? (line 17)

      Why do you set a pointer to a QVariant in your settings? (line 20)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #7

        Also, you're using "Id" in line 20, and "id" in line 21.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #8

          [quote author="Andre" date="1363711273"]# You're not telling us what is "expected", so it is hard to judge where your code deviates from your plan

          Just use a QSettings object on the stack (line 14 & 15)

          What is makegui gogoi; doing? (line 17)

          Why do you set a pointer to a QVariant in your settings? (line 20)[/quote]

          Expected is that , when user closes and restarts the application , the QLineEdit fiels already has the previously Entered Text...makegui gogoi ; declares the object of the class makegui that is responsible for making the gui part and then calling other neseccary funtions.....

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #9

            [quote author="mlong" date="1363711569"]Also, you're using "Id" in line 20, and "id" in line 21.
            [/quote]

            Fixed It :)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #10

              You can't just "bind" a QSettings value to a widget, which I think is what you're trying to do. QSettings doesn't work that way.

              You'll need to store the text from your QLineEdit by calling QSettings::setValue() each time the text changes (either as the user type it, or when you process the values -- however it's done in your gui.) This won't typically be done in main(). It is most likely best handled in your makegui class. Also, at the time you build/initialize your gui is when you'll use QSettings::value() to set your text.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #11

                [quote author="Andre" date="1363698916"]Of course. Make it persistant via storing it to a file, or using the QSettings class. Either way, you will need to load the information back on the next run.[/quote]
                Am unable to use QSettings for this...Can u guide me with the other Way of storing in A text file and then retrieving it from there?

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #12

                  Using a text file is not going to be any easier.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #13

                    Can I get a line of code that saves text of QLineedit and on restarting the app , it is retrieved ?
                    Please help , its very important for my project ...

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #14

                      No. The point is, that there isn't any such one line of code.

                      You've already been given many hints, but you refuse to take the hints given.

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #15

                        This is What was needed, its Done :)
                        @//read
                        QSettings settings("settingName");
                        QString aValue=settings.value("aKey").toString();

                        //write
                        QSettings settings("settingName");
                        QString somevalue=textedit.text();
                        settings.setValue("aKey",somevalue);
                        @

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt
                        • Unsolved