Unsolved add a numbering to each file
-
@Pl45m4 thanks for your reply bu i have this error :device not open
-
That error does not come from your string :)
How do you open your file? -
@Pl45m4
QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm");
QString folderStr = QString("Tab%1_").arg(dossier);
QString filename = folderStr + date + ".csv";
QFile file(filename);
if(!file.open(QIODevice::WriteOnly | QIODevice:: Text)) {//code
} -
@jagl said in add a numbering to each file:
file.open
So, what does open() return?
And how does filename look like? -
@jsulm
QIODevice::write (QFile, "Tab/root/Desktop/23_2021_07_07_08_40.csv"): device not open
what does filename look like means ? -
@jagl said in add a numbering to each file:
what does filename look like means ?
It means: what is the content of filename variable?
Also, can you please answer this question (asked before already): what does open() return?
"device not open" means that file was NOT opened. -
@jagl said in add a numbering to each file:
Tab/root/Desktop/
The content of your
dossier
variable is not only "Tab" but "Tab/root/Desktop/".Where shoudl your file really be after you create it?
IsTab/root/Desktop/
the file path you want?In your initial post you said, you want a filename like
Tab1_2021_07_07_07_33_55
, where the "1" in "Tab1" is a variable. -
-
@jagl Could you please read more carefully what others write?
I did not ask you what is inside the file, I asked you how the file path you are trying to use looks like! So, QFile file(filename); what is the value of filename?
And now I ask for the third (and last) time: what does open() return? -
@jagl said in add a numbering to each file:
yes i want it to be variable thats my question
I understood that, but what is your desired location for this file? Do you have a folder named "Tab"?
My solution writes a file named "Tab[i]_2021_07_07_07_33_55" to your current
QDir
location.If you wish another destination, you need to specify a valid path, which
Tab/root/Desktop/
most likely isn't.
Do you want something likeroot/Desktop/Tab/Tab1_2021_07_07_07_33_55.csv
?@jagl said in add a numbering to each file:
i have this error :device not open
@jsulm This comes from
file.open
, doesn't it? Or rather this error occures because open returned most likelyfalse
. -
@Pl45m4 said in add a numbering to each file:
doesn't it?
I would say it comes from a write attempt:
QIODevice::write (QFile, "Tab/root/Desktop/23_2021_07_07_08_40.csv"): device not open
-
@jsulm said in add a numbering to each file:
I would say it comes from a write attempt:
Ah, yes I see, because the path is no valid writeable location. @jagl messed up the path with the variable.
-
@jagl
If I copy and paste your code you haveif(!file.open(QIODevice::WriteOnly | QIODevice:: Text)) { //code }
If you truly test
! file.open()
then//code
is in the case where it does not open correctly.