当前位置: 首页>>代码示例>>C++>>正文


C++ QThread::msleep方法代码示例

本文整理汇总了C++中QThread::msleep方法的典型用法代码示例。如果您正苦于以下问题:C++ QThread::msleep方法的具体用法?C++ QThread::msleep怎么用?C++ QThread::msleep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QThread的用法示例。


在下文中一共展示了QThread::msleep方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: startServerManagerProcess

DatabaseServerError DatabaseServerStarter::startServerManagerProcess(const QString& dbType)
{
    DatabaseServerError result;

    /*
     * TODO:
     * 1. Acquire semaphore lock on "DigikamDBSrvAccess"
     * 2. Check if there is an database server manager service already registered on DBus
     * 3. If not, start the database server manager
     * 4. Release semaphore lock
     */
    QSystemSemaphore sem(QLatin1String("DigikamDBSrvAccess"), 1, QSystemSemaphore::Open);
    sem.acquire();

    if (!isServerRegistered())
    {
        const QString dbServerMgrPath = QString::fromUtf8(LIBEXEC_INSTALL_DIR) + QLatin1String("/digikamdatabaseserver");

        if ( dbServerMgrPath.isEmpty() )
        {
            qCDebug(DIGIKAM_DBENGINE_LOG) << "No path to digikamdatabaseserver set in server manager configuration!";
        }

        const QStringList arguments;

        bool result = QProcess::startDetached( dbServerMgrPath, arguments );

        if ( !result )
        {
            qCDebug(DIGIKAM_DBENGINE_LOG) << "Could not start database server manager !";
            qCDebug(DIGIKAM_DBENGINE_LOG) << "executable:" << dbServerMgrPath;
            qCDebug(DIGIKAM_DBENGINE_LOG) << "arguments:" << arguments;
        }
    }

    // wait until the server has successfully registered on DBUS
    // TODO Use another way for that! Sleep isn't good :-/

    for (int i = 0; i < 30; ++i)
    {
        if (!isServerRegistered())
        {
            QThread sleepThread;
            sleepThread.msleep(250);
            sleepThread.wait();
        }
        else
        {
            break;
        }
    }

    QDBusInterface dbus_iface(QLatin1String("org.kde.digikam.DatabaseServer"), QLatin1String("/DatabaseServer"));
    QDBusMessage stateMsg = dbus_iface.call(QLatin1String("isRunning"));

    if (!stateMsg.arguments().at(0).toBool())
    {
        DatabaseServerError error;

        QList<QVariant> arguments;
        arguments.append(dbType);

        QDBusMessage reply = dbus_iface.callWithArgumentList(QDBus::Block, QLatin1String("startDatabaseProcess"), arguments);

        if (QDBusMessage::ErrorMessage == reply.type())
        {
            result.setErrorType(DatabaseServerError::StartError);
            result.setErrorText(i18n("<p><b>Error while calling the database server starter.</b></p>"
                                     "Details:\n %1", reply.errorMessage()));
        }
        else
        {
            arguments                = reply.arguments();
            QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(arguments.at(1));
            // Retrieve the actual value stored in the D-Bus variant
            QVariant dbusArgument    = dbusVariant.variant();
            DatabaseServerError item = qdbus_cast<DatabaseServerError>(dbusArgument);
            result                   = item;
        }
    }

    sem.release();

    return result;
}
开发者ID:,项目名称:,代码行数:85,代码来源:


注:本文中的QThread::msleep方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。