#qml <-> c++ context communication options

26 messages · Page 1 of 1 (latest)

solemn shell
#

any one with qml experiences?
i have idea how to communicate between qml and c++ context in way i like
what can you say?

class FrontendConnectionSide{
Q_OBJECT
Q_PROPERTY(SomeType notifiable READ getNotifiable WRITE setNotifiable NOTIFY notifyBackend)
public:
FrontendConnectionSide(BackendConnectionSide* back){
// connect notify to backend with queued con, without magic
// connect(this,&notifyBackend,backend,&receiveFunc,Qt::queued...)
assert(back);
back_con = back;
// binded qthread of backend may be different, but if use non direct for backendCon <-> backendModules it is negligible
}

public:
// prop set get...

public slots:
void sendSomethingToBackend(){
   // my macros
   INVOKE(back, receiveSomethingFromFrontend);
}
// etc...

signals:
//properties signals...

signals:
void receiveSomethingFromBackend();

private:
SomeType notifiable;
BackendConnectionSide* back_con;

};

////

int main(){
    BackendConnectionSide* back = ...;
    FrontendConnectionSide frontendConnectionSide(back);
    engine.rootContext()->setContextProperty("frontendConnectionSide", &frontendConnectionSide);
    // connect back slots/signals to logic modules, may be in different threads
}

///////////
Item {
    Text {
        text: frontendConnectionSide.notifiable // changes will trigger something
    }

    Button {
        onClicked: frontendConnectionSide.sendSomethingToBackend()
    }

    frontendConnectionSide.receiveSomethingFromBackend.connect(function {
         ///
    })
   // or proper style
/*
    Connections {
        target: applicationData
        onDataChanged: console.log("The application data changed!")
    }
*/
}```
forest oliveBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

solemn shell
#

i like this style of communication, it is literally web without extra overhead, and also thread independent at all, if get rid of extra queued invoke then without overhead at all
i use something similar for widget app
but it just object DeepConnections:singleton{signals: void fromObject_toObject(int);}
with qml im need bridge between js and c++...
.
btw i learned something now with chatbot, may contain principal issues
struggle with normal qml tutorials

there is more options, but if possible i would like to use only frontend-backend interface
https://doc.qt.io/qt-6/qtqml-cppintegration-overview.html

solemn shell
#

!solved

forest oliveBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

vital rampart
#

Looks interesting, but doesnt this go to #1078717238678409369

solemn shell
bitter aurora
bitter aurora
# solemn shell wtf are you talking about?

/* void assert (int expression);

   If NDEBUG is defined, do nothing.
   If not, and EXPRESSION is zero, print an error message and abort.  */

#ifdef    NDEBUG

# define assert(expr)        (__ASSERT_VOID_CAST (0))

/* void assert_perror (int errnum);

   If NDEBUG is defined, do nothing.  If not, and ERRNUM is not zero, print an
   error message with the error text for ERRNUM and abort.
   (This is a GNU extension.) */

# ifdef    __USE_GNU
#  define assert_perror(errnum)    (__ASSERT_VOID_CAST (0))
# endif
solemn shell
#

are you trolling or something?

#

i have like 500+ asserts in my codebase

bitter aurora
solemn shell
#

ok, ok i got it, you just troll

bitter aurora
#

and you are still rambling

#

for no reason

steep barn
bitter aurora
steep barn
bitter aurora
#

we have a custom made assertions library at our work, and it's very good, I think

steep barn
#

yes

#

cool