我有一个包含QDateTime变量的struct tTimeMods。我有一个返回此结构的函数。我在标题中提到了一个编译错误,在compareTimeMods(tTimeMods timeTypeFunction)中的foll行: -
QString pathString = appendWithImageName(timeTypeFunction.dateTimeMod1);
你能告诉我如何解决这个问题吗?这是我的代码: -
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);
}
}
答案 0 :(得分:0)
您的appendWithImageName()
函数需要tTimeMods
类型的变量(例如timeTypeFunction
)。
您正在传入类型为timeTypeFunction.dateTimeMod1
的变量QDateTime
,因此会出错。
看起来就像您的预期电话应该改为:
QString pathString = appendWithImageName(timeTypeFunction.dateTimeMod1);
为:
QString pathString = appendWithImageName(timeTypeFunction);
因为appendWithImageName()
函数本身从传递给它的结构的dateTimeMod1
成员中提取信息。