//class counter (where the function is defined)
Counter
( QString name,
int start
= 0,
bool firstTime
= true,
QDate CreationTime
= QDate::currentDate()) :
ClickTimes(start),
name(name),
firstTime(firstTime),
lastDate
(QDate::currentDate()),
CreationTime(CreationTime)
{}
{
return lastDate.toString("dd/MM/yyyy"); //this one works perfectly
}
{
return CreationTime.toString("dd/MM/yyyy"); //this one don't
}
/*---------------------------------------------------------*/
//MainWindow.cpp
//here is where the adding (creating the counter happens)
void MainWindow::addItemToList()
{
QString text2
= ui
->inputBox_2
->text
();
//setting the model (some deleted code just to be on point)
//model properties (some deleted code just to be on point)
//adding to the model (some deleted code just to be on point)
//setting the counter
pCounters.push_back(Counter(text2,0,true));
ui->inputBox_2->clear();
}
/*---------------------------------------------------------*/
//this is where it get called
void MainWindow::SaveFile()
{
QFile Save
("streak Counter.txt");
Save.
open(QIODevice::WriteOnly|QIODevice
::Text);
for(auto i = pCounters.begin();i != pCounters.end();i++)
{
if(i->isVirigin())
{
out << i->getName() << ',' << "virigin" << ',' << i->getCreationDate() << endl; //getCreationDate() doesn't work!
}
else
{
int counterNumber = i->getNumber();
out << i
->getName
() <<
',' <<
QString::number(counterNumber
)<<
',' << i
->getDate
() <<
',' << i
->getCreationDate
() <<
"\n";
}
}
Save.close();
}
//class counter (where the function is defined)
Counter( QString name,int start = 0,bool firstTime = true,QDate CreationTime = QDate::currentDate())
:
ClickTimes(start),
name(name),
firstTime(firstTime),
lastDate(QDate::currentDate()),
CreationTime(CreationTime)
{}
QString getDate() const
{
return lastDate.toString("dd/MM/yyyy"); //this one works perfectly
}
QString getCreationDate() const
{
return CreationTime.toString("dd/MM/yyyy"); //this one don't
}
/*---------------------------------------------------------*/
//MainWindow.cpp
//here is where the adding (creating the counter happens)
void MainWindow::addItemToList()
{
QString text2 = ui->inputBox_2->text();
//setting the model (some deleted code just to be on point)
//model properties (some deleted code just to be on point)
//adding to the model (some deleted code just to be on point)
//setting the counter
pCounters.push_back(Counter(text2,0,true));
ui->inputBox_2->clear();
}
/*---------------------------------------------------------*/
//this is where it get called
void MainWindow::SaveFile()
{
QFile Save("streak Counter.txt");
Save.open(QIODevice::WriteOnly|QIODevice::Text);
for(auto i = pCounters.begin();i != pCounters.end();i++)
{
QTextStream out(&Save);
if(i->isVirigin())
{
out << i->getName() << ',' << "virigin" << ',' << i->getCreationDate() << endl; //getCreationDate() doesn't work!
}
else
{
int counterNumber = i->getNumber();
out << i->getName() << ',' << QString::number(counterNumber)<< ',' << i->getDate() << ',' << i->getCreationDate() <<"\n";
}
}
Save.close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks