简体   繁体   中英

Forward declaration of QDate class gives errors

I'm developing an application using Qt Widgets.

In my header files, I like to forward declare classes instead of including them. At the beginning of a header file I put forward declarations as follows:

class QFile;
class QDate;
class QTime;

And, there is a function declaration in the class as the following:

static bool addGoldTransaction(QFile *transactionsFile, Gold goldType, OperationType transactionType, float price, float amount, QDate date, QTime time);

When I try to compile, it gives an error like the following:

forward declaration of 'class QDate'
in definition of macro 'QT_FORWARD_DECLARE_STATIC_TYPES_ITER'
in expansion of macro 'QT_FOR_EACH_STATIC_CORE_CLASS'
In file included from moc_transaction.cpp:9:0:
error: initializing argument 6 of 'static bool addGoldTransaction(QFile*, Gold, OperationType, float, float, QDate, QTime)'

There is no error for forward declarations of other Qt-related classes.

Including the QDate header file solves the issue but I wonder:

  1. Why does the compiler complain only about QDate class while it doesn't complain about other classes? Is there anything special with QDate class related to this issue?
  2. How can I forward declare QDate class?

通过引用QDate&QTime&传递类型QDateQTime的6和7参数,或者通过const引用const QDate&const QTime& QTime&更好的参数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM