Results 1 to 6 of 6

Thread: Interacting with qt while other qt functions are running

  1. #1
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Interacting with qt while other qt functions are running

    I have a QGraphicsScene and QGraphicsView. When I click a button, QGraphicsItems will movearound in the scene. When this happens, I can't do anything else in my Qt app. How do I make it so that I can do other things while my QGraphicsItems are being updated?

    Also, I have a stop button. I want to be able to click the stop button to stop the QGraphicsItems from moving. How do I do that?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interacting with qt while other qt functions are running

    Please show us your code. You are probably blocking the event loop. You should be using the animation framework.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Interacting with qt while other qt functions are running

    Qt Code:
    1. class MainWidget(QWidget):
    2. def __init__(self):
    3. QWidget.__init__(self)
    4.  
    5. self.display = DisplayScene(self)
    6. self.view = DisplayView(self.display)
    7. self.view.show()
    8.  
    9. self.playButton = QPushButton("Play")
    10. self.stepLineEdit = QLineEdit()
    11. def Update(self):
    12. if self.display.nodeExist():
    13. if int(self.stepLineEdit.text()) < self.display.getMovementSteps():
    14. #if self.display.nodeExist():
    15. value = self.stepSizeLineEdit.text()
    16. self.stepSizeSlider.setValue(int(value))
    17. self.stepSize = value
    18. self.display.updateScene(int(self.stepLineEdit.text()))
    19. def Play(self):
    20. if self.display.nodeExist():
    21. i = int(self.stepLineEdit.text())
    22. self.display.ViewNodeMovement()
    23. totalMovementSteps = self.display.getMovementSteps()
    24. i = i + int(self.stepSize)
    25. #print totalMovementSteps
    26. while i < totalMovementSteps:
    27. self.stepLineEdit.setText(str(i))
    28.  
    29. i = i + int(math.ceil(totalMovementSteps / 1000.0))
    30. self.Update()
    31. graphViews = self.display.views()
    32. graphViews [ 0 ].repaint()
    33. self.stepLineEdit.repaint()
    34.  
    35. class DisplayScene(QGraphicsScene):
    36. def updateScene(self, index):
    37. self.currentTimeStep += index - self.currentStep
    38.  
    39. self.currentStep = index
    40.  
    41. graphViews = self.views()
    42. sceneItems = self.items()
    43. for item in sceneItems:
    44. self.removeItem(item)
    45. self.drawScene(sceneItems, graphViews)
    46. def drawScene(self, sceneItems, graphViews):
    47. nodePlatformList = [ ]
    48. for item in sceneItems:
    49.  
    50. item.setGraphView(graphViews[0])
    51. #stuff#
    52. self.addItem(item)
    To copy to clipboard, switch view to plain text mode 

    I have a good bit of code, so i cut out a lot of it. If something is not clear, just ask. Basically what happens is I have a play button, and when I click it it cycles through a while loop to update the display scene. So I guess what I want to do is to have some way to stop the while loop.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Interacting with qt while other qt functions are running

    The while loop has to go. Or at least run QApplication::processEvents() in each iteration.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Interacting with qt while other qt functions are running

    May be you should stop using while loops and use asynchronous signal/slot approach?
    -- Tanuki

    per cauda vel vaculus cauda

  6. #6
    Join Date
    Sep 2009
    Posts
    60
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Interacting with qt while other qt functions are running

    Quote Originally Posted by Tanuki-no Torigava View Post
    May be you should stop using while loops and use asynchronous signal/slot approach?
    Where can I get info to implement an asynchronous signal?

    I got it working now with a QApplication.proccessEvents(). I can click the stop button and it will stop the while loop.

Similar Threads

  1. multiple frames/widgets interacting
    By sfabel in forum Newbie
    Replies: 0
    Last Post: 6th November 2009, 04:30
  2. Interacting with a dialog started with a QProcess
    By craven in forum Qt Programming
    Replies: 6
    Last Post: 30th September 2009, 21:16
  3. Interacting with an API
    By srohit24 in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2009, 14:17
  4. qt application interacting with GSMmodem in windows
    By jjbabu in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2007, 11:22
  5. events interacting with signals/slots
    By gunhelstr in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2006, 12:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.