本文整理汇总了C++中QWaitCondition类的典型用法代码示例。如果您正苦于以下问题:C++ QWaitCondition类的具体用法?C++ QWaitCondition怎么用?C++ QWaitCondition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QWaitCondition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendEvent
void QcApplication::postSyncEvent( QcSyncEvent *e, QObject *rcv )
{
_mutex.lock();
if( !_instance ) {
_mutex.unlock();
return;
}
if( QThread::currentThread() == rcv->thread() ) {
sendEvent( rcv, e );
delete e;
}
else {
QMutex mutex;
QWaitCondition cond;
e->_cond = &cond;
e->_mutex = &mutex;
mutex.lock();
postEvent( rcv, e );
cond.wait( &mutex );
mutex.unlock();
}
_mutex.unlock();
}
示例2: ensureInitialized
CodaDevicePtr SymbianDeviceManager::getCodaDevice(const QString &port)
{
ensureInitialized();
QMutexLocker lock(&d->m_devicesLock);
const int idx = findByPortName(port);
if (idx == -1) {
qWarning("Attempt to acquire device '%s' that does not exist.", qPrintable(port));
if (debug)
qDebug() << *this;
return CodaDevicePtr();
}
SymbianDevice& device = d->m_devices[idx];
CodaDevicePtr& devicePtr = device.m_data->codaDevice;
if (devicePtr.isNull() || !devicePtr->device()->isOpen()) {
// Check we instanciate in the correct thread - we can't afford to create the CodaDevice (and more specifically, open the VirtualSerialDevice) in a thread that isn't guaranteed to be long-lived.
// Therefore, if we're not in SymbianDeviceManager's thread, rejig things so it's opened in the main thread
if (QThread::currentThread() != thread()) {
// SymbianDeviceManager is owned by the main thread
d->m_codaPortWaitMutex.lock();
QWaitCondition waiter;
QCoreApplication::postEvent(this, new QConstructCodaPortEvent((QEvent::Type)d->m_constructCodaPortEventType, port, &devicePtr, &waiter));
waiter.wait(&d->m_codaPortWaitMutex);
// When the wait returns (due to the wakeAll in SymbianDeviceManager::customEvent), the CodaDevice will be fully set up
d->m_codaPortWaitMutex.unlock();
} else {
// We're in the main thread, just set it up directly
constructCodaPort(devicePtr, port);
}
// We still carry on in the case we failed to open so the client can access the IODevice's errorString()
}
if (devicePtr->device()->isOpen())
device.m_data->deviceAcquired++;
return devicePtr;
}
示例3: doOperation
void TestInvocationPlugin::doOperation(int sleepInterval, int count)
{
for (int i = 0; i < count; ++i) {
QWaitCondition sleep;
sleep.wait(new QMutex(), sleepInterval);
}
}
示例4: msleep
/// sleep (?)
void msleep ( unsigned long millisecs ) {
QMutex mutex;
QWaitCondition waitCondition;
mutex.lock();
waitCondition.wait ( &mutex, millisecs );
mutex.unlock();
}
示例5: cap
//"Run" part of the process thread.
void ProcessThread::run()
{
VideoCapture cap(0);
if(!cap.isOpened())
{
qDebug () << "Video capture (cap) was unable to start... ";
return;
}
frame_cnt=0;
Mat matImage;
while(!(this->isStopped))
{
frame_cnt++;
cap >> matImage;
cv::resize (matImage, matImage, Size(800, 600));
//resize(matImage, image, Size(800,600));
mutex.lock();
Mat matimg = mode->process(matImage);
QImage qimg((uchar *)matimg.data, matimg.cols, matimg.rows, QImage::Format_RGB888);
QLabel *label = mode->getProperLabel();
mutex.unlock();
QWaitCondition cond;
QMutex drawMutex;
drawMutex.lock();
emit drawImage (&qimg, &cond, &drawMutex, label);
cond.wait (&drawMutex);
drawMutex.unlock();
}
};
示例6: screenShot
screengrab::screengrab()
{
// load configuration
conf = Config::instance();
conf->loadSettings();
pixelMap = new QPixmap;
scrNum = 0;
// delay on 250 msec
QMutex mutex;
mutex.lock();
QWaitCondition pause;
pause.wait(&mutex, 250);
// get screen
screenShot();
// auto saving first screenshot
if (conf->getAutoSave() == true)
{
QString format = conf->getSaveFormat();
QString filePath = getSaveFilePath(format);
writeScreen(filePath, format);
}
}
示例7: delete
void QcApplication::postSyncEvent( QcSyncEvent *e, EventHandlerFn handler )
{
_mutex.lock();
if( !_instance ) {
_mutex.unlock();
return;
}
if( QThread::currentThread() == _instance->thread() ) {
(*handler)(e);
delete(e);
}
else {
QMutex mutex;
QWaitCondition cond;
e->_handler = handler;
e->_cond = &cond;
e->_mutex = &mutex;
mutex.lock();
postEvent( _instance, e );
cond.wait( &mutex );
mutex.unlock();
}
_mutex.unlock();
}
示例8: main
int main(int argc, char *argv[])
{
#ifndef QT_DEBUG
QString fileName = FilePirate::StoragePath + "captains-log.log";
QFile *log = new QFile(fileName);
if (log->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
out = new QTextStream(log);
qInstallMsgHandler(logOutput);
} else {
qDebug() << "Error opening log file '" << fileName << "'. All debug output redirected to console.";
}
#endif
SingleApplication a(argc, argv, "9578A25E-F82A-4558-842C-1DE074F3C232");
if (a.alreadyExists()) {
qDebug() << "FilePirate is already running.";
a.sendMessage("fg");
return 0;
}
QPixmap pixmap(":/images/splash.png");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->show();
a.processEvents();
splash->showMessage("Loading...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
qDebug() << "Registering URL handler...";
QDesktopServices::setUrlHandler("pirate",&FilePirate::Application(),"handleUrl");
a.processEvents();
// Force the user to see the splash screen for at least some time
QMutex dummy;
dummy.lock();
QWaitCondition wait;
wait.wait(&dummy, 750);
dummy.unlock();
// And move on to the rest of loading
splash->showMessage("Loading settings...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
// load the settings here
FilePirate::Application().settingsLoaded = FilePirate::Application().loadSettings();
splash->showMessage("Loading local filelist...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
FilePirate::Application().fileMon->fullRefreshFileList();
// bring up the filelist - this is a good time to start up the settings dialog
// if the user hasn't done so yet...
splash->showMessage("Finishing up...",Qt::AlignCenter | Qt::AlignBottom,Qt::white);
FilePirate::Application().moveHelpersToThreads();
MainWindow w;
w.show();
splash->finish(&w);
a.connect(&a, SIGNAL(messageAvailable(QStringList)), &w, SLOT(secondInstanceMessages(QStringList)));
delete splash;
return a.exec();
}
示例9: msleep
void msleep(unsigned long msecs)
{
QWaitCondition w;
QMutex sleepMutex;
sleepMutex.lock();
w.wait(&sleepMutex, msecs);
sleepMutex.unlock();
}
示例10: sleep
void Core::sleep(int msec)
{
QMutex mutex;
mutex.lock();
QWaitCondition pause;
pause.wait(&mutex, msec); // def 240
mutex.unlock();
}
示例11: Wait
void Wait(long int time)
{
QMutex dummy;
dummy.lock();
QWaitCondition waitCondition;
waitCondition.wait(&dummy, time);
dummy.unlock();
}
示例12: msleep
void MainWindow::msleep(unsigned long msecs){
QMutex mutex;
mutex.lock();
QWaitCondition waitCondition;
waitCondition.wait(&mutex, msecs);
mutex.unlock();
}
示例13: connect
void ModelPropertyAnimation::trigger(QAbstractAnimation *animation, bool synchrone, DeletionContext deletionContext)
{
/* The connexion below won't delete indefinitely looping animation.
* To avoid memory leaks, the deletionContext paramater is introduced.
*/
connect(animation, &QAbstractAnimation::finished, [=](){animation->deleteLater();});
/* Considering what's stated in Qt's doc about Qt::AutoConnection behaviour
* (see QObject::connect), we need to make sure
* ESPECIALLY WHEN this function is called from a thread other than the gui-thread:
* from an algorithm thread for instance,
* that the animation passed as parameter leaves in the gui-thread,
* so that it can perform flawlessly.
*
* Indeed, IN THAT CASE, performing a direct call to QAbstractAnimation::start causes the animation
* not to perform in the way it should. So we first move it to the gui-thread and then
* emit a signal which finally triggers its execution.
*
* This isn't probably the best way to address this issue, but it works.
*/
// connect(this, &ModelPropertyAnimation::_startIt, animation, &QAbstractAnimation::start);
// the previous syntax doesn't work due to argument count mismatching.
connect(this, SIGNAL(_startIt()), animation, SLOT(start()));
animation->moveToThread(QApplication::instance()->thread());
auto startAnimation = [=]() { // define a function that will start the animation
emit _startIt();
// disconnect the signal, to make sure any further emission is ignored.
disconnect(this, SIGNAL(_startIt()), animation, SLOT(start()));
};
QThread *t = nullptr;
switch(deletionContext) {
case None: break;
case ThisThread: t = thread(); break;
case GuiThread: t = QApplication::instance()->thread(); break;
}
if(t) {
connect(t, &QThread::finished, animation, &QAbstractAnimation::deleteLater);
}
if(!synchrone) {
startAnimation();
}
else {
QMutex mutex;
QWaitCondition condition;
auto connexion = connect(animation, &QAbstractAnimation::finished, [&condition](){condition.wakeAll();});
mutex.lock();
startAnimation();
condition.wait(&mutex);
mutex.unlock();
disconnect(connexion);
}
}
示例14: stop
void Seq::stopWait()
{
stop();
QWaitCondition sleep;
while (state != TRANSPORT_STOP) {
mutex.lock();
sleep.wait(&mutex, 100);
mutex.unlock();
}
}
示例15: msleep
static void msleep(unsigned long msecs)
{
QMutex mutex;
mutex.lock();
QWaitCondition waitCondition;
waitCondition.wait(&mutex, msecs);
mutex.unlock();
}