Δionysus βenstein2018-05-16 19:37:31
Qt
Δionysus βenstein, 2018-05-16 19:37:31

A bunch of C++ and QML?

There is a signal in one QML file, it must interact with the C++ part, but the pluses do not find this signal, because the signal must be visible in main.qml. It is necessary in short so that I can normally connect a signal from a QML (not main) file with a slot from C ++. Question: how to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danil Asadullaev, 2018-05-19
@Benstein

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    qmlRegisterType<Calc>("com.company.calc", 1, 0, "MyCalc");
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;
    return app.exec();
}

Next, in the qml file, write import and the name of the first parameter:
import com.company.calc 1.0
// и имя элемента будет равно третьему параметру
    MyCalc {
        id: myCalcM
    }

And the class that you include must have functions declared in Q_PROPORETY or Q_INVOKABLE functions.
Q_PROPERTY(QString str READ string WRITE setString)
    Q_PROPERTY(double getResult READ StartAnalize_GetResult)

And in a JS function looks something like this:
function getResult()
{
    myCalcM.str = allStr()
    return myCalcM.getResult;
}

J
Jacob E, 2018-05-19
@Zifix

doc.qt.io/qt-5/qtqml-cppintegration-topic.html
doc.qt.io/qt-5/qtqml-cppintegration-contextpropert...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question