#include //#include "userfunc.h" #include #include #include #include #include #include #include #include #include #include //uncomment this line to add the Live Client Module and use live reloading with your custom C++ code //#include class param; QString param::table_mqtt = "mqtt"; //mqtt配置表 QString param::table_mqtt_other = "mqtt_other"; //mqtt对接配置表 QString param::table_ftp = "ftp"; //FTP配置表 QString param::table_ftp_other = "ftp_other"; //FTP对接配置表 QString param::table_camera = "camera"; //相机参数配置表 QString param::table_location = "location"; //定位信息参数配置表 QString param::table_config = "config"; //参数配置表 void traverseQmlObject(QObject *qmlObject, int depth = 0) { QString indentation = QString(" ").repeated(depth); qDebug() << indentation << "Type:" << qmlObject->metaObject()->className() << "Name:" << qmlObject->objectName(); for (QObject *child : qmlObject->children()) { traverseQmlObject(child, depth + 1); } } class MyCppClass : public QObject { Q_OBJECT public: void setQmlRootObject(QObject *rootObject) { m_qmlRootObject = rootObject; } void JumpToCamera(){ } public slots: void qmlSlot() { LOG("Received from QML"); emit recvqmlslot(); } void systemPage(){ LOG("systemPage"); emit tosystempage(); } void openbar_btnClicked(){ LOG("openbar_btnClicked"); emit opensystembar(); } void closebar_btnClicked(){ LOG("closebar_btnClicked"); emit closesystembar(); } void opennav_btnClicked(){ LOG("opennav_btnClicked"); emit opensystemnav(); } void closenav_btnClicked(){ LOG("closenav_btnClicked"); emit closesystemnav(); } signals: void recvqmlslot(); void tosystempage(); void opensystembar(); void closesystembar(); void opensystemnav(); void closesystemnav(); private: QObject *m_qmlRootObject = nullptr; }; class GPSInfo : public QObject { Q_OBJECT public: double nowGroundSpeed=0.0; double nowVerticalSpeed=0.0; double nowMagneticVariation=0.0; double nowHorizontalAccuracy=0.0; double nowVerticalAccuracy=0.0; double nowLongitude=0.0; double nowLatitude=0.0; double nowDirection=0.0; QString nowTimes=""; int recv_cnt = 0; QGeoPositionInfoSource *positionSource; public: GPSInfo(SqliteOperator *db,QObject *parent = nullptr) : QObject(parent) // 注入外部数据库对象 , gpsConfig(db) { param::gps_state = "0"; positionSource = QGeoPositionInfoSource::createDefaultSource(this); //QGeoSatelliteInfoSource *satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this); if (positionSource) { connect(positionSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo))); positionSource->setUpdateInterval(1000);//设置刷新时间 单位毫秒 positionSource->startUpdates();//启动设备 } } signals: void position_success(); private: SqliteOperator *gpsConfig = nullptr; // 不再在内部创建 private slots://槽函数中实现了GPS部分信息的读取 void positionUpdated(const QGeoPositionInfo &info) { nowLongitude = info.coordinate().longitude();//经度 nowLatitude = info.coordinate().latitude();//纬度 nowDirection = info.attribute(QGeoPositionInfo::Direction); nowGroundSpeed = info.attribute(QGeoPositionInfo::GroundSpeed); nowVerticalSpeed = info.attribute(QGeoPositionInfo::VerticalSpeed); nowMagneticVariation = info.attribute(QGeoPositionInfo::MagneticVariation); nowHorizontalAccuracy = info.attribute(QGeoPositionInfo::HorizontalAccuracy); nowVerticalAccuracy = info.attribute(QGeoPositionInfo::VerticalAccuracy); nowTimes = info.timestamp().toString(); if(param::gps_lat.contains(".")&¶m::gps_lat.size()>3){ param::gps_state = "1"; recv_cnt++; if(recv_cnt==20){ //定位成功后120S把定位信息保存到数据库中 emit position_success(); gpsConfig->OpenDb(); if(gpsConfig->isTableExist(param::table_location)){ gpsConfig->UpdateData(param::table_location,"gps_lat",param::gps_lat); gpsConfig->UpdateData(param::table_location,"gps_lng",param::gps_lng); } gpsConfig->CloseDb(); positionSource->stopUpdates(); } } param::gps_lat = QString::number(nowLatitude); param::gps_lng = QString::number(nowLongitude); LOG("经度:{}",nowLongitude); LOG("纬度:{}",nowLatitude); LOG("角度:{}",nowDirection); LOG("地表速度:{}",nowGroundSpeed); LOG("垂直速度:{}",nowVerticalSpeed); LOG("磁偏角:{}",nowMagneticVariation); LOG("水平精度:{}",nowHorizontalAccuracy); LOG("垂直精度:{}",nowVerticalAccuracy); LOG("定位次数:{}",recv_cnt); } }; void sendBroadcastFromQt(QString btn_type) { //QJniObject activity = QJniObject::callStaticObjectMethod("com/yfkj/cb/Q6iot/MyQtActivity","getCurrentActivity","()Landroid/app/Activity;"); auto qtContext = QJniObject(QNativeInterface::QAndroidApplication::context()); //activity //QJniObject qtContext = activity.callObjectMethod("getApplicationContext","()Landroid/content/Context;"); if (qtContext.isValid()) { if(btn_type=="sleep"){ QJniObject jClass("com/yfkj/bzyv1/Backlight"); //jboolean ret = jClass.callMethod("checkWriteSettingPermission","(Landroid/content/Context;I)Z",qtContext.object(),100); jClass.callMethod("setScreenLight","(Landroid/content/Context;I)V",qtContext.object(),100); } //QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr"); QJniObject jClass("com/yfkj/bzyv1/Backlight"); if(btn_type=="openbar_btn"){ jClass.callMethod("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),1); }else if(btn_type=="closebar_btn"){ jClass.callMethod("setStatusBar","(Landroid/content/Context;I)V",qtContext.object(),0); }else if(btn_type=="closenav_btn"){ jClass.callMethod("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),0); }else if(btn_type=="opennav_btn"){ jClass.callMethod("setNavigationBar","(Landroid/content/Context;I)V",qtContext.object(),1); }else if(btn_type=="imei"){ QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr"); QJniObject java_imei= jClass.callObjectMethod("getAndroidIMEI","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object()); if(java_imei.isValid()){ QString imei = java_imei.toString(); if(!imei.isEmpty()&¶m::imei.isEmpty()){ param::imei = imei; } LOG("IMEI:{}",param::imei.toStdString()); } }else if(btn_type=="csq"){ jint rsrp = QJniObject::callStaticMethod("com/yfkj/bzyv1/StatusBarCtr", "getRsrp", "(Landroid/content/Context;)I", qtContext.object()); LOG("getRsrp:{}",rsrp); }else if(btn_type=="iccid"){ QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr"); QJniObject iccid_java = jClass.callObjectMethod("getICCID","(Landroid/content/Context;)Ljava/lang/String;",qtContext.object()); if(iccid_java.isValid()){ QString iccid = iccid_java.toString(); if(!iccid.isEmpty()){ param::iccid = iccid; } LOG("ICCID:{}",param::iccid.toStdString()); } }else if(btn_type=="install"){ QJniObject jClass("com/yfkj/bzyv1/StatusBarCtr"); qDebug() << "install process start!"; jClass.callMethod("installApp","(Landroid/content/Context;)V",qtContext.object()); }else if(btn_type=="rebootSystem"){ jClass.callMethod("rebootSystem","(Landroid/content/Context;)V",qtContext.object()); }else if(btn_type=="service"){ qDebug() <<"启动android服务"; QAndroidIntent serviceIntent(qtContext.object(), "com/yfkj/bzyv1/QtAndroidService"); QJniObject result = qtContext.callObjectMethod( "startService", "(Landroid/content/Intent;)Landroid/content/ComponentName;", serviceIntent.handle().object()); } } } // 定义函数:设置每日8:00重启的定时器 auto setDailyRebootTimer = []() { // 获取当前时间(本地时间) QDateTime currentTime = QDateTime::currentDateTime(); // 构造当天8:00的目标时间(基于本地时间的0点+8小时) QDateTime targetTime = currentTime.date().startOfDay().addSecs(8 * 3600); // 8:00 = 8 * 3600秒 // 如果当前时间已过今日8:00,目标时间调整为次日8:00 if (currentTime >= targetTime) { targetTime = targetTime.addDays(1); // 加1天 } // 计算当前时间到目标时间的毫秒间隔 qint64 intervalMs = currentTime.msecsTo(targetTime); // 设置单次定时器,触发后执行重启逻辑,并重新设置下一日的定时器 QTimer::singleShot(intervalMs, []() { LOG("触发每日8:00重启"); sendBroadcastFromQt("rebootSystem"); // 发送重启广播 // 注意:若需要严格每日执行,建议在重启前重新设置定时器(根据实际需求) // 若系统重启后会自动启动本程序,可省略此处(程序重启后会重新设置定时器) // setDailyRebootTimer(); }); }; //adb shell input keyevent 26 // 224 关 // 构建权限列表 QStringList m_permissions = { "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.MANAGE_EXTERNAL_STORAGE", "android.permission.ACCESS_MEDIA_LOCATION", "android.permission.CAMERA", "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.WRITE_SETTINGS", "android.permission.READ_PHONE_STATE", "android.permission.INTERNET", "android.permission.ACCESS_NETWORK_STATE", "android.permission.WAKE_LOCK", "android.permission.VIBRATE" }; // ========== 全志A133P缓存清理函数(关键)========== void clearAllCaches() { #ifndef WIN32 QDir dir; // ========== 1. 标准缓存位置 ========== QStringList cacheLocations = { QStandardPaths::writableLocation(QStandardPaths::CacheLocation), QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation), // QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation), // QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) }; // ========== 2. Android特定缓存位置 ========== cacheLocations << QDir::homePath() + "/.cache"; cacheLocations << QDir::homePath() + "/.local/share"; // ========== 3. 所有需要清理的缓存目录 ========== QStringList cacheDirs = { "qmlsc", "qml", "rhi", "scenegraph", "shaders", "pipelines", "graphicsshadercache", "QtShaderCache", "QtQuick", "cache", "Qt", "shadercache", "textures", "graphics", "RenderCache", "ShaderCache", "TextureCache" }; QStringList cacheFileFilters = {"*.qmlc", "*.jsc", "*.cache", "*.tmp"}; // ========== 4. 遍历并清理 ========== for (const QString &cachePath : cacheLocations) { QDir cacheDir(cachePath); if (cacheDir.exists()) { qDebug() << "Scanning cache location:" << cachePath; // 清理指定目录 for (const QString &subDir : cacheDirs) { QDir sub(cacheDir.filePath(subDir)); if (sub.exists()) { sub.removeRecursively(); qDebug() << "Cleared cache directory:" << sub.absolutePath(); } } // 清理匹配的缓存文件 cacheDir.setNameFilters(cacheFileFilters); QStringList files = cacheDir.entryList(QDir::Files); for (const QString &file : files) { cacheDir.remove(file); qDebug() << "Removed cache file:" << cacheDir.filePath(file); } } } // ========== 5. 清理临时文件 ========== QDir tempDir(QDir::tempPath()); if (tempDir.exists()) { QStringList filters; filters << "Qt*" << "qml*" << "shader*" << "rhi*"; tempDir.setNameFilters(filters); QStringList tempFiles = tempDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); for (const QString &tempFile : tempFiles) { QFileInfo info(tempDir.filePath(tempFile)); if (info.isDir()) { QDir(tempDir.filePath(tempFile)).removeRecursively(); } else { tempDir.remove(tempFile); } qDebug() << "Removed temp file/dir:" << tempDir.filePath(tempFile); } } qDebug() << "All caches cleared successfully!"; #endif } int main(int argc, char *argv[]) { // ========== Android权限申请 ========== // 在应用启动时申请所有必要的权限 // 使用正确的API逐个申请权限 for (const QString &permission : m_permissions) { QtAndroidPrivate::checkPermission(permission); QtAndroidPrivate::requestPermission(permission); } INITLOG(); sendBroadcastFromQt("sleep"); QGuiApplication app(argc, argv); // ========== 第二阶段:QGuiApplication创建后再次清理缓存 ========== // 有些缓存只有在QGuiApplication创建后才能正确访问 clearAllCaches(); LOG("Second cache clear completed!"); MyCppClass myCppClass; #if WIN32 QString subDirPath = "logs/run_log.txt"; QString appDataPath ="./"; #else // 获取应用程序内部存储空间路径 QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Android/data/com.yfkj.bzyv1/files/"; LOG("appDataPath:{}",appDataPath.toStdString()); QString appPicPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/Android/data/com.yfkj.bzyv1/files/Pictures"; LOG("appPicPath:{}",appPicPath.toStdString()); #endif sendBroadcastFromQt("iccid"); sendBroadcastFromQt("csq"); //创建并打开SQLite数据库 QString db_config = "config.db"; // QString db_data = "data.db"; SqliteOperator *sqlConfig; sqlConfig = new SqliteOperator(db_config); sqlConfig->OpenDb(); //判断数据表是否存在 config_db_type config_class; if(!sqlConfig->isTableExist(param::table_mqtt)){ sqlConfig->CreateTable(param::table_mqtt); //插入数据 config_class.mqtt_db = {1,"bzy","8.136.98.49",61883,"","user","f335bf402c655ee5fd2b5300905124e","",0,60,"/yfkj/bzyL/s2c/","/yfkj/bzyL/c2s/","/yfkj/bzyL/offline/",10}; sqlConfig->InsertData(config_class,param::table_mqtt); //查询全部数据 sqlConfig->QueryAllData(param::table_mqtt); }else{ sqlConfig->QueryAllData(param::table_mqtt); } if(param::imei.isEmpty()){ sendBroadcastFromQt("imei"); QTimer::singleShot(1000, [&]() { sqlConfig->OpenDb(); if(sqlConfig->isTableExist(param::table_mqtt)){ LOG("Update imei:{}",param::imei.toStdString()); sqlConfig->UpdateData(param::table_mqtt,"imei",param::imei); } sqlConfig->CloseDb(); }); } if(!sqlConfig->isTableExist(param::table_mqtt_other)) { sqlConfig->CreateTable(param::table_mqtt_other); config_class.mqtt_db = {1,"bzy","0.0.0.0",1883,"","uid","pwd","clientid",0,60,"/yfkj/bzy/s2c/","/yfkj/bzy/c2s/","/yfkj/bzy/offline/",10}; sqlConfig->InsertData(config_class,param::table_mqtt_other); //查询全部数据 sqlConfig->QueryAllData(param::table_mqtt_other); }else{ sqlConfig->QueryAllData(param::table_mqtt_other); } if(!sqlConfig->isTableExist(param::table_ftp)) { sqlConfig->CreateTable(param::table_ftp); config_class.ftp_db = {1,"8.136.98.49",21,"","bzy_user","YFkj@6O2O",0}; sqlConfig->InsertData(config_class,param::table_ftp); sqlConfig->QueryAllData(param::table_ftp); }else{ sqlConfig->QueryAllData(param::table_ftp); } if(!sqlConfig->isTableExist(param::table_ftp_other)) { sqlConfig->CreateTable(param::table_ftp_other); config_class.ftp_db = {1,"0.0.0.0",21,"","cbd_user","YFkj@6O2O",0}; sqlConfig->InsertData(config_class,param::table_ftp_other); sqlConfig->QueryAllData(param::table_ftp_other); }else{ sqlConfig->QueryAllData(param::table_ftp_other); } if(!sqlConfig->isTableExist(param::table_location)) { sqlConfig->CreateTable(param::table_location); config_class.location_db = {1,"0","0","0","0","0"}; sqlConfig->InsertData(config_class,param::table_location); sqlConfig->QueryAllData(param::table_location); }else{ sqlConfig->QueryAllData(param::table_location); } //相机图像参数 if(!sqlConfig->isTableExist(param::table_camera)){ sqlConfig->CreateTable(param::table_camera); config_class.camera_db = {"hikrobot","static",2,1000,1000,"0","f80","b80","f80","b80"}; sqlConfig->InsertData(config_class,param::table_camera); sqlConfig->QueryAllData(param::table_camera); }else{ sqlConfig->QueryAllData(param::table_camera); } //配置 if(!sqlConfig->isTableExist(param::table_config)){ sqlConfig->CreateTable(param::table_config); config_class.config_db = {1,1,1000,500,0,0}; sqlConfig->InsertData(config_class,param::table_config); sqlConfig->QueryAllData(param::table_config); }else{ sqlConfig->QueryAllData(param::table_config); } sqlConfig->CloseDb(); //InsertJson_mqtt(); qRegisterMetaType("QByteArray"); FelgoApplication felgo; QQmlApplicationEngine engine; felgo.initialize(&engine); felgo.setLicenseKey("6BBDF824AF729C33ECAA6DC917319EDB8A7F76A9EB5217C380F81C28203CF84078DBCEEC5DB44C7DB60373C0FFE65240DA17EAC1C8376F5939F26782D2A3110CFCDB938C557DDAC8C63F942AF917CD7BCD4235973E76002E69BE740BD2FE99BB7F22AD12408FB5EE3D3A538E604803F0947C372A8486E63B5CF101A18B6CEDF7AEDC615273B15ADBCF1DCC54F123FA093609F650378D2F2BC11C74421663CAB7C178C4123AF6C8B6E44EE45A5A790448F85D4039D7EB1C23C3CA97B42E0724B2987C185114E732662A4EFD507EDC0E5DC2DA7A9FF7754678F48BFC8AAFD40B21926B5A1FD427E279FDE44EC0315229371F4D77B918CC4663CB71572051E1E84DCBF8E183C44981C9D921DB7C5A02879E2D9352ECEC03FF21D99F941B9E31E10D6D625D2603135C101658FEA17FB7B397"); LOG("信息(Info)"); TreeModel model; engine.setOfflineStoragePath(appDataPath); //设置数据库存储路径 engine.rootContext()->setContextProperty("appdir", qApp->applicationDirPath()); //使用QApplication::applicationDirPath()获取,并注册到qml中 engine.rootContext()->setContextProperty("treeModel",&model); qmlRegisterType("EasyModel",1,0,"EasyTableModel"); //注册C++模块到QML中 qmlRegisterType("com.example.database", 1, 0, "DatabaseInterface"); qmlRegisterType("ExampleCustomMaterial",1,0,"CustomItem"); // Set an optional license key from project file // This does not work if using Felgo Live, only for Felgo Cloud Builds and local builds //felgo.setLicenseKey(PRODUCT_LICENSE_KEY); // use this during development // for PUBLISHING, use the entry point below felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml")); // use this instead of the above call to avoid deployment of the qml files and compile them into the binary with qt's resource system qrc // this is the preferred deployment option for publishing games to the app stores, because then your qml files and js files are protected // to avoid deployment of your qml files and images, also comment the DEPLOYMENTFOLDERS command in the .pro file // also see the .pro file for more details //felgo.setMainQmlFileName(QStringLiteral("qrc:/qml/Main.qml")); const QUrl url(felgo.mainQmlFileName()); Qt6QCamera::Frames::registerQmlType(); SerialThread serialThread; serialThread.start(); engine.rootContext()->setContextProperty("serial", &serialThread); CurlFtpUploader uploader_ftp; // 成员变量 QString remotepath ="/photo_hard/" + param::imei; uploader_ftp.setFtpParams("bzy_user", "YFkj@6O2O", "8.136.98.49", 21, remotepath); MqttHandler mqttHandler; mqttHandler.storage()->setJsonCacheEnabled(param::jsonCacheEnable); mqttHandler.storage()->setImageCacheEnabled(param::imageCacheEnable); mqttHandler.storage()->setMaxJsonEntries(param::maxJsonEntries); mqttHandler.storage()->setMaxImageEntries(param::maxImageEntries); CurlHandler curlHandler("ftp://8.136.98.49/_UPDATE_FILE/Android/BZYV2/armv7a/app.apk",appDataPath+"/app.apk"); //app升级 NetworkInfoHelper networkMonitor; engine.rootContext()->setContextProperty("mqtt", &mqttHandler); engine.rootContext()->setContextProperty("curl", &curlHandler); //engine.rootContext()->setContextProperty("ymodem",serialThread.getYmodem()); engine.rootContext()->setContextProperty("curl_picture",&uploader_ftp); engine.rootContext()->setContextProperty("networkMonitor", &networkMonitor); QObject::connect(&serialThread,&SerialThread::dataUpload,&mqttHandler,&MqttHandler::publish_m); //串口到MQTT QObject::connect(&mqttHandler,&MqttHandler::dataReceived,&serialThread,&SerialThread::mqtttoserial);//MQTT到串口 QObject::connect(&networkMonitor,&NetworkInfoHelper::reachabilityChanged,[&](QNetworkInformation::Reachability newReachability){ if(newReachability==QNetworkInformation::Reachability::Online){ WARN("网络连接!"); param::net_alive = 1; }else{ param::net_alive = 0; WARN("网络断开!"); mqttHandler.disconnectFromBroker(); } }); QObject::connect(&uploader_ftp, &CurlFtpUploader::finished, &mqttHandler,&MqttHandler::storage_Picture); QObject::connect(&mqttHandler, &MqttHandler::signal_reupload_image, &uploader_ftp,&CurlFtpUploader::uploadFileAsync); QObject::connect(&mqttHandler, &MqttHandler::signal_upload_log, &uploader_ftp,&CurlFtpUploader::uploadFileAsync); QObject::connect(&mqttHandler,&MqttHandler::updateStm32,[&](){ curlHandler.seturl("ftp://8.136.98.49/_UPDATE_FILE/A7/STM32/Application_BZYV2.rbl"); curlHandler.setfilepath(appDataPath+"/rtthread.rbl"); curlHandler.settype("主板升级文件更新"); curlHandler.start(); //sendBroadcastFromQt("install"); }); QObject::connect(&mqttHandler,&MqttHandler::appdownload,[&](){ curlHandler.seturl("ftp://8.136.98.49/_UPDATE_FILE/Android/BZYV2/app.apk"); //curlHandler.setfilepath(appDataPath+"/app.apk"); curlHandler.setfilepath("/sdcard/app.apk"); curlHandler.settype("App升级文件更新"); curlHandler.start(); // }); QObject::connect(&mqttHandler,&MqttHandler::sysReboot,[&](){ WARN("系统重启"); sendBroadcastFromQt("rebootSystem"); }); QObject::connect(&mqttHandler,&MqttHandler::configChange,[&](){ sqlConfig->OpenDb(); if(sqlConfig->isTableExist(param::table_camera)){ qDebug() << "UpdateData stitch_photonum !!!!!"; sqlConfig->UpdateData(param::table_camera,"stitch_photonum",QString::number(param::stitch_photonum)); } sqlConfig->CloseDb(); }); QObject::connect(&mqttHandler,&MqttHandler::signal_imei_change,[&](QString NEW_IMEI){ sqlConfig->OpenDb(); if(sqlConfig->isTableExist(param::table_mqtt)){ LOG("Update Data imei:{}",NEW_IMEI.toStdString()); sqlConfig->UpdateData(param::table_mqtt,"imei",NEW_IMEI); } sqlConfig->CloseDb(); }); QObject::connect(&curlHandler,&CurlHandler::downloadFinished,[&](bool result,QString mtype){ LOG("downloadFinished:{}-{}",result,mtype.toStdString()); if(result&&mtype.contains("App")){ // QByteArray download_success("{\"cmd\":\"warn\",\"ext\":{\"status\":\"App DownLoad Success!\"}}"); // mqttHandler.publish_m(download_success); emit mqttHandler.appInstall(); } }); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); // 将位置信息源暴露给QML界面 engine.load(QUrl(felgo.mainQmlFileName())); //FelgoLiveClient liveClient(&engine); //UserFunc myClass(engine.rootObjects()); // 获取QML对象 #if WIN32 app.installNativeEventFilter(myClass.mySerialEvent); // 安装window串口拔插事件 #endif //engine.rootContext()->setContextProperty("myClass", &myClass); // 将C++类添加进QML使用 //engine.rootContext()->setContextProperty("mySerial", myClass.serial_main); // 将C++类添加进QML使用 QObject *rootItem = engine.rootObjects().value(0); //traverseQmlObject(rootItem); #if 1 if(rootItem) { QObject::connect(&mqttHandler,&MqttHandler::autotakephoto,[&](bool stat){ QObject *Navigation_main = rootItem->findChild("Navigation_main"); if(Navigation_main){ qDebug() << "Navigation_main is !!!!!"<findChild("autoFocus_Page"); if(autoFocus_Page){ QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,stat)); //将param::stitchphoto保存 } } }); //mqtt到QML,控制qml跳转到自动对焦界面,开始对焦拍照 QObject::connect(&serialThread,&SerialThread::auto_takephoto,[&](){ QObject *Navigation_main = rootItem->findChild("Navigation_main"); if(Navigation_main){ qDebug() << "Navigation_main is !!!!!"; QMetaObject::invokeMethod(Navigation_main, "setCurrentTab", Q_ARG(QVariant, 1)); //打开相机 QObject *autoFocus_Page = rootItem->findChild("autoFocus_Page"); if(autoFocus_Page){ QMetaObject::invokeMethod(autoFocus_Page, "autotake",Q_ARG(QVariant,true)); } } }); //串口到QML,控制qml跳转到自动对焦界面,结束对焦拍照 //获取按钮点击事件 QObject *systemset_Item = rootItem->findChild("systemset_Item"); if(systemset_Item){ QObject::connect(systemset_Item, SIGNAL(selected()),&myCppClass,SLOT(systemPage())); QObject::connect(&myCppClass, &MyCppClass::tosystempage,[&](){ QObject *openbar_btn = rootItem->findChild("openbar_btn"); //打开状态栏 if(openbar_btn){ QObject::connect(openbar_btn, SIGNAL(opernBar()),&myCppClass,SLOT(openbar_btnClicked())); QObject::connect(&myCppClass, &MyCppClass::opensystembar,[&](){ sendBroadcastFromQt("openbar_btn"); }); QObject::connect(openbar_btn, SIGNAL(closeBar()),&myCppClass,SLOT(closebar_btnClicked())); QObject::connect(&myCppClass, &MyCppClass::closesystembar,[&](){ sendBroadcastFromQt("closebar_btn"); }); } QObject *opennav_btn = rootItem->findChild("opennav_btn"); //控制导航栏 if(opennav_btn){ QObject::connect(opennav_btn, SIGNAL(opernNav()),&myCppClass,SLOT(opennav_btnClicked())); QObject::connect(&myCppClass, &MyCppClass::opensystemnav,[&](){ sendBroadcastFromQt("opennav_btn"); }); QObject::connect(opennav_btn, SIGNAL(closeNav()),&myCppClass,SLOT(closenav_btnClicked())); QObject::connect(&myCppClass, &MyCppClass::closesystemnav,[&](){ sendBroadcastFromQt("closenav_btn"); }); } }); } // 获取根 QML 对象 QObject *autofocus_item = rootItem->findChild("autofocus_Item"); if(autofocus_item){ bool isConnect_frame = true; //const QMetaObject *metaObj = autofocus_item->metaObject(); LOG("Found autofocus_item!"); QObject::connect(autofocus_item, SIGNAL(selected()),&myCppClass,SLOT(qmlSlot())); QObject::connect(&myCppClass, &MyCppClass::recvqmlslot,[&](){ LOG("connect myCppClass"); Qt6QCamera::Frames *m_frames = qobject_cast(rootItem->findChild("Frames")); if(!m_frames) {ERROR("m_frames is null!!!");} if(m_frames&&isConnect_frame){ LOG("m_frames connected!"); //engine.addImageProvider("ucamera",m_frames->getImageProvider()); QObject::connect(m_frames,&Qt6QCamera::Frames::serial_data,&serialThread,&SerialThread::sendData); //Frame到串口 QObject::connect(&serialThread,&SerialThread::takephotodone,m_frames,&Qt6QCamera::Frames::saveImage); //串口到QML,控制qml跳转到自动对焦界面 //QObject::connect(m_frames,&Qt6QCamera::Frames::signal_stitch,&imagestitcher,&ImageStitcher::stitch_thread); QObject::connect(&serialThread,&SerialThread::signal_movy,m_frames,&Qt6QCamera::Frames::onMovDone); QObject::connect(m_frames,&Qt6QCamera::Frames::dataUpload,&mqttHandler,&MqttHandler::publish_m); //frames到MQTT // 修改信号槽连接方式 QObject::connect(m_frames, &Qt6QCamera::Frames::signal_wait_upload, &uploader_ftp, &CurlFtpUploader::uploadFileAsync); QObject::connect(&uploader_ftp, &CurlFtpUploader::finished, m_frames,&Qt6QCamera::Frames::handle_reult_upload); isConnect_frame = false; }else{ ERROR("m_frames no !!!!!"); } }); }else{ qDebug() << "autofocus_item no !!!!!"; } }else{ ERROR("rootItem is null !!!!!"); } #endif LOG("app start!"); // to start your project as Live Client, comment (remove) the lines "felgo.setMainQmlFileName ..." & "engine.load ...", // and uncomment the line below //FelgoLiveClient client (&engine); GPSInfo *gps_start = new GPSInfo(sqlConfig,&app); QObject::connect(gps_start,&GPSInfo::position_success,[&](){ emit serialThread.gpsSuccess(); }); return app.exec(); } #include "main.moc"