本文整理汇总了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();
}
}
示例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();
}