crow-translate / QOnlineTranslator

A library for Qt5 that provides free usage of Google, Yandex and Bing translate API.
GNU General Public License v3.0
78 stars 13 forks source link

Error compiling QOnlineTranslator::toJson() #14

Closed Light-Wizzard closed 3 years ago

Light-Wizzard commented 3 years ago

I get the following error in after adding QOnlineTranslator to my project:

src/qonlinetranslator.cpp:282: error: undefined reference to `QOption::toJson() const'

The error is in this file: https://github.com/crow-translate/QOnlineTranslator/blob/master/src/qonlinetranslator.cpp

The lines involved are here:

QJsonDocument QOnlineTranslator::toJson() const

QJsonArray arr;
for (const QOption &option : it.value())
{
    arr.append(option.toJson());
}

QOption is defined here: https://github.com/crow-translate/QOnlineTranslator/blob/master/src/qoption.h

Here is the problem: toJson is not a member of QJsonObject

struct QOption
{
    QString word;
    QString gender;
    QStringList translations;
    QJsonObject toJson() const;
};

QOption: https://github.com/crow-translate/QOnlineTranslator/blob/master/docs/QOption.md

QJsonObject QOption::toJson()

toJson() is not a member of QJsonObject: https://doc.qt.io/qt-5/qjsondocument.html

QJsonDocument Class shows toJson as a Member: https://doc.qt.io/qt-5/qjsondocument.html, and that did not work due to this void QJsonArray::append(const QJsonValue&).

I only see that you added this function to it, but nothing after that, does anyone have an idea how to fix it, I am using the latest Qt Creator.

Thanks, Flesh

Shatur commented 3 years ago

Here is the problem: toJson is not a member of QJsonObject

toJson is a member of QOption, not QJSon. I can compile the project successfully using CMake.

But I think I know what the problem is. Are you probably using QMake? I noticed that I forgot to add qoption.cpp and qoption.h to qonlinetranslator.pri. Will fix it today after work or you can send a PR.

Light-Wizzard commented 3 years ago

I used qmake, I need to convert to cmake since it is the future of Qt 6, add in qexample and it works great, I should have looked at cmake, it was in the path and pulling in the code at compile time but was not linking to it because it was not part of the project, and we call that Intellisence, you have to love it and qexample throw me off, it seems redundant and was throwing the same error, so it must be an example of how to extend your own class, and was no issue after adding in qoption and qexample to the pri.

Thanks, Flesh

Shatur commented 3 years ago

Yes, I also switched to CMake. But QMake should also work now.