Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Something wrong with QWaitCondition
Forum Updated to NodeBB v4.3 + New Features

Something wrong with QWaitCondition

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yvvan
    wrote on last edited by
    #1

    For a long time i compiled my program only on Linux with qt 4.6.2. But then decided to watch it on my windows xp using qt creator with qt 4.7.0. What happened: on linux every signal was sent to gui thread and waked second thread, but in windows it (sending signal) worked only for 1-4 times and then second thread went to wait condition forever.
    I have main gui thread and second thread, that calls wait() function for lots of times.

    in my second thread:
    @
    ther is class Finder

    QWaitCondition wCond;
    QMutex sync;
    QImage img;
    void imageRecieved(QImage screenshot);
    signals:
    void needScreenshot();

    void Finder::wait()
    {
    QTest::qSleep(50);
    sync.lock();
    emit needScreenshot();
    wCond.wait(&sync);
    sync.unlock();
    }
    void Finder::imageRecieved(QImage screenshot)
    {
    img = screenshot;
    wCond.wakeOne();
    }
    @

    @
    in main gui thread

    Finder* finder;

    QObject::connect(finder, SIGNAL(needScreenshot()),SLOT(makeScreeshot()));

    void makeScreeshot()
    {
    unsigned long windowId;
    windowId=sc.getHeroesWinId(mainWinForm_.lineEdit->text());//returns window id depends on system, i can list it's code if needed
    if(windowId == 0)
    {
    QImage img;
    finder->imageRecieved(img);
    return;
    }
    QPixmap pixmap = QPixmap::grabWindow((WId)windowId);
    QImage img(pixmap.toImage());
    finder->imageRecieved(img);
    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      I don't know what exactly is your problem, but

      I would use QMutexLocker lock(&sync); in wait().

      In imageRecieved() I would do the same:

      @
      void Finder::imageRecieved(QImage screenshot)
      {
      QMutexLocker lock(&sync);
      img = screenshot;
      wCond.wakeOne();
      }
      @

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved