QGC源码阅读-1

从main.cc开始

//-----------------------------------------------------------------------------
/**
 * @brief Starts the application
 *
 * @param argc Number of commandline arguments
 * @param argv Commandline arguments
 * @return exit code, 0 for normal exit and !=0 for error cases
 */

int main(int argc, char *argv[])
{
#ifndef __mobile__
    // We make the runguard key different for custom and non custom
    // builds, so they can be executed together in the same device.
    // Stable and Daily have same QGC_APPLICATION_NAME so they would
    // not be able to run at the same time
    QString runguardString(QGC_APPLICATION_NAME);
    runguardString.append("RunGuardKey");

    qDebug()<<"argc: "<<argc; 
    for(int i = 0; i < argc; ++i) {
        qDebug()<<"argv["<<i<<"]: "<<argv[i]; 
    }
    qDebug()<<"runguardString: "<<runguardString; 

    RunGuard guard(runguardString);
    if (!guard.tryToRun()) {
        // QApplication is necessary to use QMessageBox
        QApplication errorApp(argc, argv);
        QMessageBox::critical(nullptr, QObject::tr("Error"),
            QObject::tr("A second instance of %1 is already running. Please close the other instance and try again.").arg(QGC_APPLICATION_NAME)
        );
        return -1;
    }
#endif

    //-- Record boot time
    QGC::initTimer();

    // install the message handler
    AppMessages::installHandler();

#ifdef Q_OS_WIN
    // Set our own OpenGL buglist
    qputenv("QT_OPENGL_BUGLIST", ":/opengl/resources/opengl/buglist.json");

    // Allow for command line override of renderer
    for (int i = 0; i < argc; i++) {
        const QString arg(argv[i]);
        if (arg == QStringLiteral("-angle")) {
            QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
            break;
        } else if (arg == QStringLiteral("-swrast")) {
            QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
            break;
        }
    }
#endif

    // The following calls to qRegisterMetaType are done to silence debug output which warns
    // that we use these types in signals, and without calling qRegisterMetaType we can't queue
    // these signals. In general we don't queue these signals, but we do what the warning says
    // anyway to silence the debug output.
#ifndef NO_SERIAL_LINK
    qRegisterMetaType<QSerialPort::SerialPortError>();
#endif
    qRegisterMetaType<QAbstractSocket::SocketError>();
#ifndef __mobile__
#ifndef NO_SERIAL_LINK
    qRegisterMetaType<QGCSerialPortInfo>();
#endif
#endif

    qRegisterMetaType<Vehicle::MavCmdResultFailureCode_t>("Vehicle::MavCmdResultFailureCode_t");

    // We statically link our own QtLocation plugin

#ifdef Q_OS_WIN
    // In Windows, the compiler doesn't see the use of the class created by Q_IMPORT_PLUGIN
#pragma warning( disable : 4930 4101 )
#endif

    Q_IMPORT_PLUGIN(QGeoServiceProviderFactoryQGC)

    bool runUnitTests = false;          // Run unit tests

    QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    QGCApplication* app = new QGCApplication(argc, argv, runUnitTests);
    Q_CHECK_PTR(app);
    if(app->isErrorState()) {
        app->exec();
        return -1;
    }

    // There appears to be a threading issue in qRegisterMetaType which can cause it to throw a qWarning
    // about duplicate type converters. This is caused by a race condition in the Qt code. Still working
    // with them on tracking down the bug. For now we register the type which is giving us problems here
    // while we only have the main thread. That should prevent it from hitting the race condition later
    // on in the code.
    qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >();

    app->_initCommon();
    //-- Initialize Cache System
    getQGCMapEngine()->init();

    int exitCode = 0;

    {
        if (!app->_initForNormalAppBoot()) {
            return -1;
        }
        exitCode = app->exec();
    }

    app->_shutdown();
    delete app;
    //-- Shutdown Cache System
    destroyMapEngine();

    qDebug() << "After app delete";

    return exitCode;
}

* RunGuard-防止同一版本的多个程序同时运行

We make the runguard key different for custom and non custom builds, so they can be executed together in the same device.Stable and Daily have same QGC_APPLICATION_NAME so they would not be able to run at the same time。

这里打印int argc,char *argv[]得到:

argc:  1
argv[ 0 ]:  D:\Work\qgc4.2.9\build-qgroundcontrol-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\staging\QGroundControl.exe

这个打印结果是正常的,我使用的是qt creator直接运行的,没有用命令行添加指令参数运行。新创建一个qt项目打印这两项也基本一样,argv是可执行程序的路径。

先来看main函数中的第一段代码:

    QString runguardString(QGC_APPLICATION_NAME);
    runguardString.append("RunGuardKey");

    RunGuard guard(runguardString);
    if (!guard.tryToRun()) {
        // QApplication is necessary to use QMessageBox
        QApplication errorApp(argc, argv);
        QMessageBox::critical(nullptr, QObject::tr("Error"),
            QObject::tr("A second instance of %1 is already running. Please close the other instance and try again.").arg(QGC_APPLICATION_NAME)
        );
        return -1;
    }

QGC_APPLICATION_NAMEqgroundcontrol.pro,也就是Qt工程文件中中定义:

DEFINES += QGC_APPLICATION_NAME=
  • 20
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Windows QGC是指在Windows操作系统上运行的QGroundControl软件。安装Windows QGC的步骤如下: 1. 首先,你需要安装Visual Studio 2015(VS2015)和Git。你可以从以下网址下载它们:VS2015镜像下载网址:https://msdn.itellyou.cn/;Git下载网址:https://git-scm.com/downloads。 2. 接下来,你需要用Git下载QGroundControl的源代码。你可以在https://github.com/mavlink/qgroundcontrol下载。 3. 最后,你需要下载和安装Qt。你可以从http://download.qt.io/archive/qt下载Qt。 4. 在安装过程中,可能需要通过联网下载一些安装包。如果需要,只需点击联网获取即可。 5. 在使用Git克隆源代码时,可能会出现克隆失败或下载速度缓慢的情况。这可能是由于网络不稳定。你可以使用Ctrl+C终止克隆,然后利用上一次的命令来重新克隆,以节省输入。 6. 在使用Qt进行编译时,可能会出现一些错误。例如,“rc”不是内部或外部命令,也不是可运行的程序或批处理文件。这是由于没有安装Windows Web开发工具。你可以打开安装Visual Studio的程序,进行相应的更改。另外,可能还会出现“cl”不是内部或外部命令,也不是可运行的程序或批处理文件的错误。这是因为没有将Visual Studio中VC文件夹下的bin路径添加到系统的环境变量中。解决这些问题后,你可以在Qt Creator的工具栏的构建选项下,先点击“清理项目”,然后点击“执行qmake”,最后点击“重新构建项目”。如果编译成功并且可以运行,那么你将可以使用QGroundControl了。 请注意,有些提示只是警告,不影响软件的运行。只要能够成功编译并运行,你就可以使用Windows QGC了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [windows下新版QGC地面站环境搭建全面攻略(v4.1.x QGroundControl地面站搭建,附源码百度网盘)](https://blog.csdn.net/qq_16504163/article/details/107035685)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [WIN10源码编译安装QGC-V3.4](https://blog.csdn.net/wangz_/article/details/82502387)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值