我有一个包含 QDateTime 变量的结构 tTimeMods。我有一个返回这个结构的函数。如标题中所述,我在 compareTimeMods(tTimeMods timeTypeFunction) 内的 foll 行中收到一个编译错误:-
QString pathString = appendWithImageName(timeTypeFunction.dateTimeMod1);
你能告诉我如何解决这个问题吗?这是我的代码:-
主窗口.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
主窗口.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);
}
}