add a numbering to each file
-
My problem is simple but I don't see the solution I created a csv file with the date and time which will be saved in a folder my problem I just want to add a numbering to each file by exp:
when i click in the button for the first time, file name will be: Tab1_2021_07_07_07_33_55
2nd time will be: Tab2_2021_07_07_07_33_55
3rd time will be : Tab3_2021_07_07_07_33_55
code:
QString filenameTab = QDateTime :: currentDateTime () .toString (QString ("'% 1 / Tab_'yyyy_MM_dd' _ 'hh_mm'.csv"). Arg (folder)); -
My problem is simple but I don't see the solution I created a csv file with the date and time which will be saved in a folder my problem I just want to add a numbering to each file by exp:
when i click in the button for the first time, file name will be: Tab1_2021_07_07_07_33_55
2nd time will be: Tab2_2021_07_07_07_33_55
3rd time will be : Tab3_2021_07_07_07_33_55
code:
QString filenameTab = QDateTime :: currentDateTime () .toString (QString ("'% 1 / Tab_'yyyy_MM_dd' _ 'hh_mm'.csv"). Arg (folder));QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm"); QString folderStr = QString("Tab%1_").arg(folder); QString filenameTab = folderStr + date + ".csv";
Then just increase the
folder
int counter every time you click your button. -
QString date = QDateTime::currentDateTime().toString("yyyy_MM_dd_hh_mm"); QString folderStr = QString("Tab%1_").arg(folder); QString filenameTab = folderStr + date + ".csv";
Then just increase the
folder
int counter every time you click your button. -
@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
} -
@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? -
@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. -
@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:
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 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
. -
@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
-
@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
-
@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
}