Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved] A brute qtextstram-autodeleter
Forum Updated to NodeBB v4.3 + New Features

[Solved] A brute qtextstram-autodeleter

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 2 Posters 3.5k 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.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    let us see this snippet:
    @
    void Seconda::writeNewSection(QString linguaOrigine, QString linguaFinale)
    {
    linguaOrigine[0] = linguaOrigine[0].toUpper();
    linguaFinale[0] = linguaFinale[0].toUpper();
    if(linguaFinale.compare("Tedesco") == 0 || linguaFinale.compare("Deutsch") == 0)
    {
    QString tmp = linguaFinale;
    linguaFinale = linguaOrigine;
    linguaOrigine = tmp;
    }
    QString lingue = linguaOrigine + " " + linguaFinale;
    QFile f(QDir::currentPath() + "/listaSezioni.txt");
    if(f.open(QIODevice::Append | QIODevice::Text | QIODevice::ReadWrite))
    {
    QTextStream stream (&f);
    if(stream.readAll().contains(lingue))
    {
    f.close();
    emit signal_return();
    }
    else
    {
    qDebug()<<"nuovo testo: "<< lingue;
    stream.seek(0);
    stream << lingue << '\n';
    f.close();
    terza *t = new terza(linguaOrigine, linguaFinale);
    t->show();
    this->close();
    }
    }
    }
    @

    there is a problem. here we go! as the file is opened, the datas that occour to me are deleted. please, prove it and say me what is borrough. as for me it is a perfect code!

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

      Sorry, I don't understand what's your problem. Can you rephrase it, please: What do you expect in your file, what do you get?

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spode
        wrote on last edited by
        #3

        stream.readAll(); returns "", although the file contains a lot of strings.

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

          Ah, of course. You open the file using mode QIODevice::Append - that will position the file "cursor" at the end, and of course there's nothing left to read ;-)

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            spode
            wrote on last edited by
            #5

            xD i am a "distrattone" (italian). i thank you a lot!! =)

            EDIT:
            @
            void cinque::writeNewWord(QString l1, QString l2, QString genere, QString wort, QString beispiel, QString parola, QString esempio)
            {
            if(wort.isEmpty() && beispiel.isEmpty() && parola.isEmpty() && esempio.isEmpty())
            {
            Prima *d = new Prima();
            d->show();
            this->close();
            }
            else
            {
            if(l1.compare("Deutsch") != 0 || l1.compare("Tedesco") != 0) genere = "";
            wort[0] = wort[0].toUpper();

                QFile f(QDir::currentPath() + "listaSezioni.txt");
                //aggiunta del nuovo biglietto al file listaSezioni.txt
                if(f.open(QIODevice::Text | QIODevice::ReadOnly))
                {
                    QTextStream streami(&f);
                    streami.seek(0);
                    QString separatore = " | ";
                    QStringList listaSezioni;
                    QString riga;
                    do {
                        riga = streami.readLine();
                        qDebug() << "riga: " << riga;
                        if(riga.contains(l1) && riga.contains(l2))
                        {
                            listaSezioni.append(riga);
                            listaSezioni.append(genere + separatore + wort + separatore + beispiel + separatore + parola + separatore + esempio + '\n');
                        }
                        else listaSezioni.append(riga);
                    }while(!streami.atEnd());
                    f.close();
            

            @

            ahm, 'xcuse me, what about here? riga = streami.readLine(); qDebug() << "riga: " << riga;
            output: "riga: "" "

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

              Hard to say without knowing the actual contents of the file :)

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

              1 Reply Last reply
              0
              • S Offline
                S Offline
                spode
                wrote on last edited by
                #7

                the actual content is:
                @
                *Tedesco Italiano\n
                das Haus | das haus ist schon | casa | \n
                der Hund | | cane | \n
                *Inglese Italiano\n
                @

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

                  The code works for me.

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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    spode
                    wrote on last edited by
                    #9

                    here we go, dear Volker!!
                    @
                    QFile f(QDir::currentPath() + "listaSezioni.txt");
                    @
                    should be
                    @
                    QFile f(QDir::currentPath() + "/listaSezioni.txt");
                    @

                    "/" is the issue!! =)

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

                      Ah, that little typos - they are know to steal you a whole day of debugging - welcome to the club :-)

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

                      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