Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with synchronizing calls to grabToImage()
Forum Updated to NodeBB v4.3 + New Features

Problem with synchronizing calls to grabToImage()

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.3k 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.
  • P Offline
    P Offline
    peteritv
    wrote on last edited by
    #1

    Hi guys!

    Please bear with me, I am pretty new at this stuff...

    I built a playing card editor in QML (QtQuick 2.7), and use Item.grabToImage() to save a card as a png image.
    The good news: This works fine!

    Now I want to expand the functionality by changing some of the card parameters (e.g. suit, rank, 52 cards in a deck) in a for loop,
    and save all all variants. Let's say card[0] is ace of spades, and card[51] is two of clubs with all the other cards in between.

    for (int i = 0; i<52; i++) {
       changeParameters(specific for each card);
       card.grabToImage(saveSingle, Qt.size(cWidth,cHeight));
    }
    

    The only thing the callback function (saveSingle) does is the actual Image.saveToFile();

    The problem is that grabToImage() is asynchronous, and the for loop already finished before the first image gets a chance to be saved! Since the two of clubs is the last card in the loop, the callback function gets called 52 times with the same image...

    Any ideas on how to synchronize the for loop with the callback function, so that I get 52 different images?

    Thanks in advance!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about triggering the changeParameters in your callBack and then call again grabToImage ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • P Offline
        P Offline
        peteritv
        wrote on last edited by
        #3

        Hi SGaist,

        Thanx for your reply!

        I have been playing around a lot yesterday, and decided that I need to have some form of storage to keep all the parameter changes (I will serialize those later on), so I was thinking about letting the for-loop just fill a list model (1 list element has all parameters needed to recreate a card).

        After that I will call grabToImage() once to get things started, and the callback can then keep things going itself while emptying the list.

        So I guess that is basically the same as your suggestion, right?
        Thanks again!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Yep, that's similar.

          You're welcome !

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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