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. Access to the user interface
Forum Updated to NodeBB v4.3 + New Features

Access to the user interface

Scheduled Pinned Locked Moved General and Desktop
25 Posts 2 Posters 4.8k 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.
  • L Offline
    L Offline
    leon2225
    wrote on last edited by
    #16

    No it isn't ... it still have the problem that it couldn't read the data from the files.

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

      Rather than
      @
      QTextStream in(&file);
      setItsContent(in.readAll());@

      Why not just:
      @
      setItsContent(file.readAll());
      @

      In any case, are you sure that your file is not empty ?

      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
      • L Offline
        L Offline
        leon2225
        wrote on last edited by
        #18

        That doesn't work... And the file isn't empty

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

          Did you check what file.readAll() contains ?

          since setItsContent only assign the parameter value to your itsContent member variable why not just do:

          @itsContent = file.readAll()@

          ?

          By the way, you should use const QString& in your setItsContent function, that will avoid unnecessary copies.

          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
          • L Offline
            L Offline
            leon2225
            wrote on last edited by
            #20

            Okey ehm file.readAll() return the right content of the file, the problem is, that it doesn't convert it into QString. readAll() gives back a QByteArray wich normaly could be converted in QString with for example:
            @itsContent = QString(file.readAll());@

            But it doesn't ...

            here is the function again:
            @bool Data::openContent(bool customFileName){
            if(itsContentFilename.isEmpty() || customFileName)
            itsContentFilename= QFileDialog::getOpenFileName(MyFxhnn, tr("Inhalt öffnen"), QString(), tr("Fxhnn Content Files (*.txt)"));

            if(!itsContentFilename.isEmpty()){
                QFile file(itsContentFilename);
                if(!file.open(QIODevice::ReadOnly)){
                    QMessageBox::critical(MyFxhnn, tr("Error"), tr("Could not open file"));
                    return false;
                }
                QTextStream in(&file);
                QMessageBox::information(MyFxhnn, "Content of readAll(", file.readAll());
                itsContent = QString(file.readAll());
                QMessageBox::information(MyFxhnn, "Content of itsContent", QString(file.readAll()));
                printItsContent();
                file.close();
            
                if((itsContent != MyFxhnn -> ui -> itsText -> toPlainText()) || itsContent == ""){
                    QMessageBox::critical(MyFxhnn, tr("Error"), tr("Fehler beim Öffnen, Data != Textfeld"));
                    return false;
                }
            }
            
            
            return true;
            

            }@

            The Message "Content of readAll()" gives back the right content the other message return nothing an the last error message appears.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon2225
              wrote on last edited by
              #21

              Now it's working a 'bit'.
              It is able to read the file and print it into the output, BUT it doesn't save onicode ... and I need unicode so we have to find an other solution :/ :D

              1 Reply Last reply
              0
              • L Offline
                L Offline
                leon2225
                wrote on last edited by
                #22

                Now it's working a 'bit'.
                It is able to read the file and print it into the output, BUT it doesn't save onicode ... and I need unicode so we have to find an other solution :/ :D
                @bool Data::openContent(bool customFileName){
                if(itsContentFilename.isEmpty() || customFileName)
                itsContentFilename= QFileDialog::getOpenFileName(MyFxhnn, tr("Inhalt öffnen"), QString(), tr("Fxhnn Content Files (*.txt)"));

                if(!itsContentFilename.isEmpty()){
                    QFile file(itsContentFilename);
                    if(!file.open(QIODevice::ReadOnly)){
                        QMessageBox::critical(MyFxhnn, tr("Error"), tr("Could not open file"));
                        return false;
                    }
                    //QTextStream in(&file);
                    //QMessageBox::information(MyFxhnn, "Inhalt von readAll()", file.readAll());
                    QByteArray tempString = file.readAll();
                    itsContent = tempString;
                    QMessageBox::information(MyFxhnn, "Inhalt von itsContent", itsContent);
                    printItsContent();
                    file.close();
                
                    if((itsContent != MyFxhnn -> ui -> itsText -> toPlainText()) || itsContent == ""){
                        QMessageBox::critical(MyFxhnn, tr("Error"), tr("Fehler beim Öffnen, Data != Textfeld"));
                        return false;
                    }
                }
                
                
                return true;
                

                }@

                and here are the printItsContent():
                @void Data::printItsContent(){
                //MyFxhnn -> ui -> itsText->clear(); <- If I uncomment this line it clear the output text, but it can't set it again
                MyFxhnn -> ui -> itsText -> setPlainText(itsContent);
                setItsEncryptLevel(0);
                setItsShuffleLevel(0);
                return;
                }@

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

                  That's the kind of detail that's good to share.

                  Then it seems that you should use QTextCodec

                  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
                  • L Offline
                    L Offline
                    leon2225
                    wrote on last edited by
                    #24

                    OK!
                    now it works, but only with textstream, but that's enough.

                    Thank you!! :)

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

                      What do you mean by "only with textstream" ?

                      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

                      • Login

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