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


C++ MyThread::sleep方法代码示例

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


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

示例1: error

void RfCommClient::error(QBluetoothSocket::SocketError err)
{
    qDebug() << __PRETTY_FUNCTION__ << "Got socket error" << err;
    // remote side has closed the socket, effectively disconnecting it
    if (state == pendingConnections) {
        state = dataTransfer;
        emit disconnected();
        stopClient();

        // now reconnect and send text string
        MyThread mythread;
        mythread.sleep(5);
        startClient(serviceInfo);
        connect(&lagTimer, SIGNAL(timeout()), this, SLOT(sendText()));
        lagTimer.start();
    } else {
        qDebug() << __PRETTY_FUNCTION__ << "emitting done";
        emit done();
    }
}
开发者ID:lainwir3d,项目名称:qtconnectivity,代码行数:20,代码来源:rfcommclient.cpp

示例2: main

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);    
    RfCommClient client;
    QBluetoothLocalDevice localDevice;
    MyThread mythread;
    
    QObject::connect(&client, SIGNAL(done()), &app, SLOT(quit()));

    QString address;
    QString port;
    QStringList args = QCoreApplication::arguments();
    
    if(args.length() >= 2){
        address = args.at(1);
        if(args.length() >= 3){
            port = args.at(2);
        }
    }

       // use previous value for client, stored earlier
//    if(address.isEmpty()){
//        QSettings settings("QtDF", "bttennis");
//        address = settings.value("lastclient").toString();
//    }

    // hard-code address and port number if not provided
    if(address.isEmpty()){
        address = "6C:9B:02:0C:91:D3";  // "J C7-2"
        port = QString("20");
    }
            
    if(!address.isEmpty()){
        qDebug() << "Connecting to" << address << port;
        QBluetoothDeviceInfo device = QBluetoothDeviceInfo(QBluetoothAddress(address), "", 
                QBluetoothDeviceInfo::MiscellaneousDevice);
        QBluetoothServiceInfo service;
        if (!port.isEmpty()) {
            QBluetoothServiceInfo::Sequence protocolDescriptorList;
            QBluetoothServiceInfo::Sequence protocol;
            protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
                     << QVariant::fromValue(port.toUShort());
            protocolDescriptorList.append(QVariant::fromValue(protocol));
            service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
                                 protocolDescriptorList);
            qDebug() << "port" << port.toUShort() << service.protocolServiceMultiplexer();
        }
        else {
            service.setServiceUuid(QBluetoothUuid(serviceUuid));
        }
        service.setDevice(device);
        // delay so that server is in waiting state
        qDebug() << "Starting sleep";
        mythread.sleep(10);  // seconds
        qDebug() << "Finished sleeping";
        client.startClient(service);
    } else {
        qDebug() << "failed because address and/or port is missing " << address << port;
    }

    
    return app.exec();
}
开发者ID:ionionica,项目名称:qt-mobility,代码行数:63,代码来源:main.cpp


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