Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] How to set the changed text as default text? (for lineEdit)
Forum Updated to NodeBB v4.3 + New Features

[solved] How to set the changed text as default text? (for lineEdit)

Scheduled Pinned Locked Moved General and Desktop
15 Posts 5 Posters 11.3k 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.
  • I Offline
    I Offline
    Immii
    wrote on last edited by
    #5

    Your constructor or init() method shoule look something like this:
    @
    myClass::myClass()
    {
    QString defText=readSettings();
    If(defText==NULL)
    myLientEdit.setText("Default Text")
    else
    myLineEdit.setText(defText);
    }

    myClass::~myClass()
    {
    saveSettings();
    }
    @
    Hope this clarifies further.

    [Edit: set indents into code / Vass]

    1 Reply Last reply
    0
    • J Offline
      J Offline
      justforfun
      wrote on last edited by
      #6

      [quote author="peppe" date="1293300321"]What's the default text you're talking about? the "placeholderText"?[/quote]

      No. I mean 'text' filed of a lineEdit.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        justforfun
        wrote on last edited by
        #7

        Hi, Milot Shala & Immii, thank you for your information!
        I used the say method, an 'ini' file of QSettings to solve my question and got what I want. Below is my code.

        @void MainWindow::on_setButton_clicked()
        {
        QSettings settings("myconfig.ini", QSettings::IniFormat);

        QString str_1 = ui->lineEdit_offset0->text();
        settings.setValue("offset0", str_1);
        QString str0 = ui->lineEdit_value0->text();
        settings.setValue("value0", str0);
        ...
        

        }

        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);

        QFileInfo fi("myconfig.ini");
        if (fi.exists())
        {
            QSettings settings("myconfig.ini", QSettings::IniFormat);
        
            QString str_1 = settings.value("offset0").toString();
            ui->lineEdit_offset0->setText(str_1);
            QString str0 = settings.value("value0").toString();
            ui->lineEdit_value0->setText(str0);
            ...
         }
        

        }@

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Immii
          wrote on last edited by
          #8

          [quote author="justforfun" date="1293371341"]Hi, Milot Shala & Immii, thank you for your information!
          I used the say method, an 'ini' file of QSettings to solve my question and got what I want. Below is my code.
          [/quote]

          I am glad so will be Milot Shala that your problem is solved. Please mark this thread solved.:)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #9

            justforfun, just as a simplification: "QSettings::value() ":http://doc.trolltech.com/stable/qsettings.html#value takes an optional second parameter for a default value. This way you can always read from your settings, regardless if it exists or not.

            Also, in line 20 you check for file "myconfig.ini" in line 23 you open "ulsconfig.ini". Seems to be a typo when preparing the code for the forum here, but better have a check.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • J Offline
              J Offline
              justforfun
              wrote on last edited by
              #10

              [quote author="Volker" date="1293385022"]justforfun, just as a simplification: "QSettings::value() ":http://doc.trolltech.com/stable/qsettings.html#value takes an optional second parameter for a default value. This way you can always read from your settings, regardless if it exists or not.

              Also, in line 20 you check for file "myconfig.ini" in line 23 you open "***config.ini". Seems to be a typo when preparing the code for the forum here, but better have a check.[/quote]

              Hi Volker, thank you for your hint! That is a good way, I learn it from you now.
              As fro the typo, you are right. I corrected it.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                justforfun
                wrote on last edited by
                #11

                [quote author="Immii" date="1293382684"]
                [quote author="justforfun" date="1293371341"]Hi, Milot Shala & Immii, thank you for your information!
                I used the say method, an 'ini' file of QSettings to solve my question and got what I want. Below is my code.
                [/quote]

                I am glad so will be Milot Shala that your problem is solved. Please mark this thread solved.:)[/quote]

                Added.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  milot.shala
                  wrote on last edited by
                  #12

                  Good to hear that the problems was solved. Please don't forget to mark this thread as [SOLVED]

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    justforfun
                    wrote on last edited by
                    #13

                    [quote author="Milot Shala" date="1293441272"]Good to hear that the problems was solved. Please don't forget to mark this thread as [SOLVED][/quote]

                    Hi, I pressed the 'Tag -> solved' already, is it right?

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      milot.shala
                      wrote on last edited by
                      #14

                      [quote author="justforfun" date="1293442179"]
                      [quote author="Milot Shala" date="1293441272"]Good to hear that the problems was solved. Please don't forget to mark this thread as [SOLVED][/quote]

                      Hi, I pressed the 'Tag -> solved' already, is it right?

                      [/quote]

                      You can change the title as well, just prepend the [SOLVED] before the actual title.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        justforfun
                        wrote on last edited by
                        #15

                        [quote author="Milot Shala" date="1293442420"]
                        [quote author="justforfun" date="1293442179"]
                        [quote author="Milot Shala" date="1293441272"]Good to hear that the problems was solved. Please don't forget to mark this thread as [SOLVED][/quote]

                        Hi, I pressed the 'Tag -> solved' already, is it right?

                        [/quote]

                        You can change the title as well, just prepend the [SOLVED] before the actual title.[/quote]

                        Done.

                        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 Extensions
                        • Unsolved