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

Doesn't work when use it inside other classes instead of main.cpp #1

Closed LinArcX closed 4 years ago

LinArcX commented 4 years ago

Hi. i want to use your library inside my app. but i don't want to use itin this way(since my app is qt-quick and uses qml/c++ in same time. so i connect every cpp class to a qml file):

QCoreApplication app(argc, argv);
...
QOnlineTranslator translator;
translator.translate("Hello world", QOnlineTranslator::Google);

QObject::connect(&translator, &QOnlineTranslator::finished, [&] {
    if (translator.error() == QOnlineTranslator::NoError)
        qInfo() << translator.translation();
    else
        qCritical() << translator.errorString();
});

Actually it works only in main.cpp and after this line: QCoreApplication app(argc, argv);

I want to use it in other c++ classes that connect them to qml pages. how do that?

Shatur commented 4 years ago

It just an example. You can use it inside every class. I use it inside MainWindow. Just create QOnlineTranslator instance, it works as any other QObject. And yes, you need to create an application object first in main.cpp.

LinArcX commented 4 years ago

Thank you so much.