C++ (Qt)#include <QApplication>#include <QQmlApplicationEngine> #include "myclass.h" int main(int argc, char *argv[]){ QApplication app(argc, argv); qmlRegisterType<MyClass>("mytest", 1, 0, "Mytest"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec();}
C++ (Qt) import mytest 1.0; ... Mytest { id: my_test; ... }
C++ (Qt)bool my_class::hasConnection(){ QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces(); foreach (const QNetworkInterface &interface, interfaces) { if (interface.flags().testFlag(QNetworkInterface::IsUp) && !interface.flags().testFlag(QNetworkInterface::IsLoopBack)) if (interface.addressEntries().length()) return true; } return false;}