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. what is happening here ? what is MY CODING ERROR ?
Forum Updated to NodeBB v4.3 + New Features

what is happening here ? what is MY CODING ERROR ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 465 Views 2 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    Here is my under construction code

    if (file.open(QIODevice::ReadWrite | QIODevice::Text))
    {

                        qDebug()<< "DEBUG   source " << source;
                        qDebug()<< "BEFORE DEBUG  destination " << destination;
                        QTextStream outStream(&destination);
                        outStream << source;
                        qDebug()<< "DEBUG   source " << source;
                        //qDebug()<< "DEBUG  destination r" << destination;
                        qDebug()<< "AFTER DEBUG  destination " << destination;
                        qDebug()<< "AFTER DEBUG  destination " << destination;r
                        return source;
                    }
                    else
                    {
                        qDebug()<<"\033[0;31m ";
                        qDebug()<< "\nDEBUG FAILED to open stream file  ";
                        qDebug()<<"\033[0;30m ";
                        return source;
    
     and here us my QDebug output         
    
       Why do I have "source + destination" AFTER 
    
     **outStream << source;**
    

    my task is to output "source" text line to file @ destination and that is not happening

    what am I doing wrong ?

    DEBUG source "TEST LINE"
    BEFORE DEBUG destination "../../BT_DATABASE/BluetoothComboData.txt"
    DEBUG source "TEST LINE"
    AFTER DEBUG destination "../../BT_DATABASE/BluetoothComboData.txtTEST LINE"
    AFTER DEBUG destination "../../BT_DATABASE/BluetoothComboData.txtTEST LINE"

    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      Here is my under construction code

      if (file.open(QIODevice::ReadWrite | QIODevice::Text))
      {

                          qDebug()<< "DEBUG   source " << source;
                          qDebug()<< "BEFORE DEBUG  destination " << destination;
                          QTextStream outStream(&destination);
                          outStream << source;
                          qDebug()<< "DEBUG   source " << source;
                          //qDebug()<< "DEBUG  destination r" << destination;
                          qDebug()<< "AFTER DEBUG  destination " << destination;
                          qDebug()<< "AFTER DEBUG  destination " << destination;r
                          return source;
                      }
                      else
                      {
                          qDebug()<<"\033[0;31m ";
                          qDebug()<< "\nDEBUG FAILED to open stream file  ";
                          qDebug()<<"\033[0;30m ";
                          return source;
      
       and here us my QDebug output         
      
         Why do I have "source + destination" AFTER 
      
       **outStream << source;**
      

      my task is to output "source" text line to file @ destination and that is not happening

      what am I doing wrong ?

      DEBUG source "TEST LINE"
      BEFORE DEBUG destination "../../BT_DATABASE/BluetoothComboData.txt"
      DEBUG source "TEST LINE"
      AFTER DEBUG destination "../../BT_DATABASE/BluetoothComboData.txtTEST LINE"
      AFTER DEBUG destination "../../BT_DATABASE/BluetoothComboData.txtTEST LINE"

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @AnneRanch said in what is happening here ? what is MY CODING ERROR ?:

      if (file.open(QIODevice::ReadWrite | QIODevice::Text))

      QTextStream outStream(&destination);

      You show no relationship between file and destination. Show your declaration/initialisation of destination. By the look of it it is a string, your code will not output to a file of that name/your file variable. Maybe you intended QTextStream outStream(&file);, as per https://doc.qt.io/qt-6/qtextstream.html#details ?

      1 Reply Last reply
      1
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        I am going to guess that destination is a QByteArray containing "../../BT_DATABASE/BluetoothComboData.txt".
        That QByteArray is associated with a QTextStream using this constructor. Writing to the stream appends to the QByteArray, and that is what you are seeing.

        A 1 Reply Last reply
        2
        • C ChrisW67

          I am going to guess that destination is a QByteArray containing "../../BT_DATABASE/BluetoothComboData.txt".
          That QByteArray is associated with a QTextStream using this constructor. Writing to the stream appends to the QByteArray, and that is what you are seeing.

          A Offline
          A Offline
          Anonymous_Banned275
          wrote on last edited by
          #4

          @ChrisW67 No, the destination is QString holding the actual text file.

          As far as
          "You show no relationship between file and destination. "
          That statement really does not address the issue.
          Compiler would complain without such relations.

          I went back to the original example and installed several copies - no problem.
          I just cannot see what is wrong with my "bad" code.

          Christian EhrlicherC JonBJ 2 Replies Last reply
          0
          • A Anonymous_Banned275

            @ChrisW67 No, the destination is QString holding the actual text file.

            As far as
            "You show no relationship between file and destination. "
            That statement really does not address the issue.
            Compiler would complain without such relations.

            I went back to the original example and installed several copies - no problem.
            I just cannot see what is wrong with my "bad" code.

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @AnneRanch said in what is happening here ? what is MY CODING ERROR ?:

            "You show no relationship between file and destination. "
            That statement really does not address the issue.

            lol - simply ignoring the facts seems to be very popular in the us nowadays :D

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • M Offline
              M Offline
              mchinand
              wrote on last edited by
              #6

              Show the code where you instantiate source and destination (and any assignments before the code you show above). Appending the contents of source to that of destination is the expected result of outStream << source in your code.

              1 Reply Last reply
              0
              • A Anonymous_Banned275

                @ChrisW67 No, the destination is QString holding the actual text file.

                As far as
                "You show no relationship between file and destination. "
                That statement really does not address the issue.
                Compiler would complain without such relations.

                I went back to the original example and installed several copies - no problem.
                I just cannot see what is wrong with my "bad" code.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @AnneRanch said in what is happening here ? what is MY CODING ERROR ?:

                That statement really does not address the issue.

                It is 100% the issue.

                I just cannot see what is wrong with my "bad" code.

                I already said. Why don't you try

                QTextStream outStream(&file);
                

                (instead of QTextStream outStream(&destination);) which is what you want? Can't see how to state it any clearer than that.

                In your code the QTextStream outStream(&destination); means that you are putting the output stream into the variable which holds a pathname, not to the file you opened, not what you intended at all. Hence the debug output you see.

                1 Reply Last reply
                1

                • Login

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