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. Big problem in reading&writing binary files
QtWS25 Last Chance

Big problem in reading&writing binary files

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.4k Views
  • 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
    sajastu
    wrote on last edited by
    #1

    hi,
    i have a big problem in qt, assume that i use binary files and write data to them.
    my data are strings,
    and i want them string (in output mode) whenever i read them.
    any help will be appreciated :)
    thanks in advance.

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

      Hi,
      On your QFile pointer you could set a QByteArray and check out that class to define how do you need that data from the file. The fromHex en toHex jump to mind in your case.
      Greetz

      Greetz, Jeroen

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

        Thanks for your reply,
        look, this is my code :

        for writing:
        [code]

        QString strToWrite = ui->User_signUp->text()+ui->Pass_signUp->text();
        QFile fileToWrite("users.dat");
        QDataStream dataStreamWriter(&fileToWrite);
        fileToWrite.open(QIODevice::WriteOnly);
        dataStreamWriter << strToWrite;
        fileToWrite.close();

        [/code]

        and for reading:

        [code]
        QString strToRead= "";
        QFile fileToRead("users.dat");
        QDataStream dataStreamReader(&fileToRead);
        fileToRead.open(QIODevice::ReadOnly);
        dataStreamReader >> strToRead;
        fileToRead.close();

            qDebug() << strToRead;
        

        [/code]

        but in this case problem is that qDebug does'nt work.

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

          Hi and welcome to devnet,

          Is it a typo or are you really writing to users.bin and reading from file.bin ?

          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
          • S Offline
            S Offline
            sajastu
            wrote on last edited by
            #5

            Sorry i change the code with QByteArray,

            for writing:

            [code]

            QByteArray ar=ui->User_signUp->text().toUtf8()+"%"+ ui->Pass_singUp->text().toUtf8()+"$";
            QFile file("users.dat");
            file.open(QIODevice::WriteOnly | QIODevice::Append );
            file.write(ar);

            [/code]

            this code writes the usernames and passwords correctly

            Now assume that i want to search a specified String(username) in my file, I think i can do this by using 2 QByteArrays, one for the username (which user has entered) and another for the file which reads whole file.
            but i don't know how i can use them. could you help me?

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

              Are you thinking about QByteArray::contains ?

              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