0

我有一个包含 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);
        }
    }
4

1 回答 1

0

您的appendWithImageName()函数需要一个类型的变量tTimeMods(例如timeTypeFunction)。

相反,您传递的timeTypeFunction.dateTimeMod1是 type的变量QDateTime,因此会出现错误。

看起来您的预期调用应该从:

QString pathString = appendWithImageName(timeTypeFunction.dateTimeMod1);

至:

QString pathString = appendWithImageName(timeTypeFunction);

因为该appendWithImageName()函数本身dateTimeMod1从传递给它的结构成员中提取信息。

于 2014-02-17T04:16:17.123 回答