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. Save Adress and Load automatically
Forum Updated to NodeBB v4.3 + New Features

Save Adress and Load automatically

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.4k 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.
  • Z Offline
    Z Offline
    zheka777
    wrote on last edited by
    #1

    Hey all,
    i need some help please.
    Here is a little programm:
    !http://s1.directupload.net/images/131104/p5xazoki.jpg(picture)!

    What the programm should do?

      1. I write a String (16 characters for example: SWT1:SET:YV:LKN=5404) into the textEdit Widget.
      1. Afterthat i want to save this Adress
      1. I press the Button "Speichern" [Save]
      1. Now programm should save this adress in a .txt file or similar file AND the adress must be written in the combobox now. So for example I saved 5 Adresses, so the combobox must have 5 Adresses, that i can select...
    • programm should load saved adresses (.txt file) automatically when I do start the programm

    Can someone help me please`?

    Hochschule Kempten

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Two ways to do so, use the QFile with QTextStream to store/read data from a text file.
      Otherwise use QSettings class to store the files in registery/ini file etc depending on OS used.
      Hope this gives some idea what to do.
      Greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zheka777
        wrote on last edited by
        #3

        EDIT: Or maybe more easyer:

        I save the QStrings in the ComboBox... Someone idea how to do?


        Yes, thaks for your answer...
        But can someone give me a concret exapmle please?

        The first what I have to do is to read the text from the textbox:
        @void MainWindow::speichereText(QString text) {
        QString a;
        a = (ui->lineEdit_3->text());
        text = a;
        }@
        The second step: I have to write it into the .txt File:
        HOW?
        @QFile file("out.txt");
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
        return;

        QTextStream out(&file);
        out << "The magic number is: " << 49 << "\n";@
        

        How Can I include here the Text, that i read from textbox?

        The third: I have to write this text from .txt file in the Combobox as a List:
        Here I dont also know HOW I can combine the text from .txt to ComboBox

        Hochschule Kempten

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Please, have a look at the documentation, "QComboBox::addItem":http://qt-project.org/doc/qt-5.0/qtwidgets/qcombobox.html#addItem

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Hi,
            Don't expect us to code the simplest of things. The QFile and QCombobox documentation is perfectly clear, but since your a noob, I give it a short example code:
            @
            void MainWindow::SaveDataToFile(QComboBox * Box_p)
            {
            int NmbrOfItems (0);

            if (Box_p->count() > 0)
            {
                // STart a file &#40;try static function for new/open file?
                QFile File_fl(&"Your filename here"&#41;;
                QTextStream outFile(&File_fl&#41;;
                
                if (File_fl.open(QIODevice::ReadWrite&#41; == true)
                {
                    // We have items in the list
                    for (NmbrOfItems = 0; NmbrOfItems < Box_p->count(); NmbrOfItems++)
                    {
                        Box_p->setCurrentIndex(NmbrOfItems);
                        // Add all items to the file
                        outFile << Box_p->currentText();
                        outFile << "/n";    // or any other seperation character!
                    }
                }            
            }
            

            }
            @
            The reading of data goes the same way, but then do read from file until end.

            Greetz, Jeroen

            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