what is happening here ? what is MY CODING ERROR ?
-
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" -
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"@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
fileanddestination. Show your declaration/initialisation ofdestination. By the look of it it is a string, your code will not output to a file of that name/yourfilevariable. Maybe you intendedQTextStream outStream(&file);, as per https://doc.qt.io/qt-6/qtextstream.html#details ? -
I am going to guess that
destinationis 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. -
I am going to guess that
destinationis 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.@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. -
@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.@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
-
@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.@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.