Here's a custom class I implemented for a personal project:
#include <QtCore/QCommandLineOption>
#include <QtCore/QSharedPointer>
#include <genepy/cli/CommandLineArgument.h>
#include <genepy/cli/CommandLineOption.h>
class QCommandLineParser;
namespace genepy {
class CommandLineParserBuilder;
class ConsoleApplication;
class GENEPY_EXPORT CommandLineParser {
public:
static CommandLineParserBuilder create(const ConsoleApplication& application);
void doParsing();
template <typename T>
T getArgumentValue(const QString& name) const;
bool isOptionPresent(const QString& name) const;
template <typename T>
T getOptionValue(const QString& name) const;
private:
friend class CommandLineParserBuilder;
explicit CommandLineParser(const ConsoleApplication& application);
const QSharedPointer<QCommandLineParser> parser_;
const QCommandLineOption helpOption_;
const QCommandLineOption versionOption_;
QVector<CommandLineArgument> arguments_;
QVector<CommandLineOption> options_;
};
} // namespace genepy
The complete code can be found here.
When I compile this code with Qt 5.15 on Windows (MinGW, MSVC), there's no problem. However, on Debian 9 with Qt 5.7, I get this error :
In file included from /home/erwan/git/genepy/include/genepy/cli/CommandLineParserBuilder.h:29:0,
from /home/erwan/git/genepy/src/cli/CommandLineParser.cpp:29:
/home/erwan/git/genepy/include/genepy/cli/CommandLineParser.h:94:34: error: field ‘arguments_’ has incomplete type ‘QVector<genepy::CommandLineArgument>’
QVector<CommandLineArgument> arguments_;
^~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1139:0,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qalgorithms.h:43,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:43,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstringlist.h:41,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qcommandlineparser.h:43,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/QCommandLineParser:1,
from /home/erwan/git/genepy/src/cli/CommandLineParser.cpp:26:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qtypeinfo.h:189:1: note: declaration of ‘class QVector<genepy::CommandLineArgument>’
Q_DECLARE_MOVABLE_CONTAINER(QVector);
^
In file included from /home/erwan/git/genepy/include/genepy/cli/CommandLineParserBuilder.h:29:0,
from /home/erwan/git/genepy/src/cli/CommandLineParser.cpp:29:
/home/erwan/git/genepy/include/genepy/cli/CommandLineParser.h:97:32: error: field ‘options_’ has incomplete type ‘QVector<genepy::CommandLineOption>’
QVector<CommandLineOption> options_;
^~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1139:0,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qalgorithms.h:43,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:43,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstringlist.h:41,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qcommandlineparser.h:43,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/QCommandLineParser:1,
from /home/erwan/git/genepy/src/cli/CommandLineParser.cpp:26:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qtypeinfo.h:189:1: note: declaration of ‘class QVector<genepy::CommandLineOption>’
Q_DECLARE_MOVABLE_CONTAINER(QVector);
^
I've no clue on what's going wrong with this code... Can someone help me? Thank you very much for your help.
Finally, I changed QVector<CommandLineArgument>
to QVector<QSharedPointer<CommandLineArgument>>
since CommandLineArgument
wasn't an assignable data type (it was missing a default constructor among others). Now, it works.