I have a struct tTimeMods which contains QDateTime variables. I have a function which returns this struct. I get one compilation error as mentioned in the title, at the foll line inside compareTimeMods(tTimeMods timeTypeFunction):-
QString pathString = appendWithImageName(timeTypeFunction.dateTimeMod1);
Can you please advise me how to solve this? Here's my code:-
mainwindow.h
#define UPDATED_IMAGE_STORAGE_PATH "E:\\QT1\\timeStampWithDateModified\\timeStampWithDateModified\\updatedRefImg.jpg"
#define SLEEP_TIME 2000
typedef struct
{
QDateTime dateTimeMod1;
QDateTime dateTimeMod2;
}tTimeMods;
tTimeMods timeTypeFunction, timeTypeMain;
tTimeMods findTimeModified(); //returns a struct
void compareTimeMods(tTimeMods timeTypeFunction); //takes struct as parameter
QString appendWithImageName(tTimeMods timeTypeFunction);//takes struct as parameter
mainwindow.cpp
tTimeMods findTimeModified()
{
QString myFileName = UPDATED_IMAGE_STORAGE_PATH;
QFileInfo info(myFileName);
/*find last date modified*/
//QDateTime dateTimeMod1, dateTimeMod2;
timeTypeFunction.dateTimeMod1 = info.lastModified();
timeTypeFunction.dateTimeMod2 = info.lastModified();
/*find last time modified*/
//QDateTime timeMod1, timeMod2;
// timeTypeFunction.timeMod1 = (timeTypeFunction.dateTimeMod1).time();
// timeTypeFunction.timeMod2 = timeTypeFunction.dateTimeMod2.time();
/*return the time part of date time*/
qDebug()<< "dateTimeMod1: " << timeTypeFunction.dateTimeMod1.toString() << endl << "dateTimeMod2: "<< timeTypeFunction.dateTimeMod2.toString();
// qDebug()<< "timeMod1: " << timeTypeFunction.timeMod1.toString() << endl << "timeMod2: "<< timeTypeFunction.timeMod2.toString();
return(timeTypeFunction);
}
void compareTimeMods(tTimeMods timeTypeFunction)
{
//if(timeMod2 > timeTypeFunction)
if(timeTypeFunction.dateTimeMod2 > timeTypeFunction.dateTimeMod1)
{
timeTypeFunction.dateTimeMod1 = timeTypeFunction.dateTimeMod2;
QString pathString = appendWithImageName(timeTypeFunction.dateTimeMod1);
shiftToRepository(pathString);
}
}
QString appendWithImageName(tTimeMods timeTypeFunction)
{
/*appending just the timeMod with the path & image name*/
QString path = QString("E:\\QT1\\timeStampWithDateModified\\timeStampWithDateModified\\backUp\\updatedRefImg[%1].jpg").arg(timeTypeFunction.dateTimeMod1.toString());
return path;
//qDebug()<< "path: " << path;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//QDateTime timeModified = findDateModified(); //CHECK->this shud give two QDateTime variables to compateTimeMods
timeTypeMain = findTimeModified();
while(1)
{
Sleep(SLEEP_TIME);
compareTimeMods(timeTypeMain);
}
}
Your appendWithImageName()
function requires a variable of type tTimeMods
(such as timeTypeFunction
).
You are instead passing in a variable timeTypeFunction.dateTimeMod1
which is of type QDateTime
, hence the error.
It looks like your intended call should be changed from:
QString pathString = appendWithImageName(timeTypeFunction.dateTimeMod1);
to:
QString pathString = appendWithImageName(timeTypeFunction);
since that appendWithImageName()
function itself extracts the information from the dateTimeMod1
member of the structure passed to it.