Results 1 to 5 of 5

Thread: QApplication Process seems to hang

  1. #1
    Join Date
    Jul 2020
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QApplication Process seems to hang

    Hello,

    I'm a somewhat programming and python nooby and I have to implement a pipeline in my institut. A researcher create a dataviewer in the tutorial file using PyQt5 but even the test-function push the process into a hanging state (kernel is forced to restart after the window is terminated). i.e. it creates a pop-up window with the correct name and resolution but the window itself is black without any widgets and it halts immediately.

    I know it's a somewhat impossible mission to find the solution but maybe someone got a climse of a idea what I could try next.

    Qt Code:
    1. class DataViewer(pg.QtGui.QWidget):
    2. def __init__(self, source, axis = None, scale = None, title = None, invertY = False, minMax = None, screen = None, parent = None, *args):
    3.  
    4. ### Print pointer to QApplication Instance (we now know that at this time a QApp is initalized)
    5. print(pg.QtGui.QApplication.instance())
    6. print(pg.QtGui.QApplication.allWidgets())
    7.  
    8. ### Images soures
    9. self.initializeSources(source, axis = axis, scale = scale)
    10. #print('init')
    11. ### Gui Construction
    12. pg.QtGui.QWidget.__init__(self, parent, *args);
    13. #print('gui')
    14.  
    15. if title is None:
    16. if isinstance(source, str):
    17. title = source;
    18. elif isinstance(source, io.src.Source):
    19. title = source.location;
    20. if title is None:
    21. title = 'DataViewer';
    22. self.setWindowTitle(title);
    23. self.resize(1600,1200)
    24. #print('title')
    25.  
    26.  
    27. self.layout = pg.QtGui.QGridLayout(self);
    28. self.layout.setContentsMargins(0,0,0,0)
    29. #print('layout')
    30.  
    31. # image pane
    32. self.view = pg.ViewBox();
    33. self.view.setAspectLocked(True);
    34. self.view.invertY(invertY)
    35.  
    36. self.graphicsView = pg.GraphicsView()
    37. self.graphicsView.setObjectName("GraphicsView")
    38. self.graphicsView.setCentralItem(self.view)
    39.  
    40. splitter = pg.QtGui.QSplitter();
    41. splitter.setOrientation(pg.QtCore.Qt.Horizontal)
    42. splitter.setSizes([self.width() - 10, 10]);
    43. self.layout.addWidget(splitter);
    44.  
    45. image_splitter = pg.QtGui.QSplitter();
    46. image_splitter.setOrientation(pg.QtCore.Qt.Vertical)
    47. image_splitter.setSizePolicy(pg.QtGui.QSizePolicy.Expanding, pg.QtGui.QSizePolicy.Expanding)
    48. splitter.addWidget(image_splitter);
    49. #print('image')
    50.  
    51. # Image plots
    52. image_options = dict(clipToView = True, autoDownsample = True, autoLevels = False, useOpenGL = None);
    53. self.image_items = [pg.ImageItem(s[self.source_slice[:s.ndim]], **image_options) for s in self.sources];
    54. for i in self.image_items:
    55. i.setRect(pg.QtCore.QRect(0, 0, self.source_range_x, self.source_range_y))
    56. i.setCompositionMode(pg.QtGui.QPainter.CompositionMode_Plus);
    57. self.view.addItem(i);
    58. self.view.setXRange(0, self.source_range_x);
    59. self.view.setYRange(0, self.source_range_y);
    60. #print('plots')
    61.  
    62. # Slice Selector
    63. self.slicePlot = pg.PlotWidget()
    64. sizePolicy = pg.QtGui.QSizePolicy(pg.QtGui.QSizePolicy.Preferred, pg.QtGui.QSizePolicy.Preferred)
    65. sizePolicy.setHorizontalStretch(0)
    66. sizePolicy.setVerticalStretch(0)
    67. sizePolicy.setHeightForWidth(self.slicePlot.sizePolicy().hasHeightForWidth())
    68. self.slicePlot.setSizePolicy(sizePolicy)
    69. self.slicePlot.setMinimumSize(pg.QtCore.QSize(0, 40))
    70. self.slicePlot.setObjectName("roiPlot");
    71. #self.sliceCurve = self.slicePlot.plot()
    72.  
    73. self.sliceLine = pg.InfiniteLine(0, movable=True)
    74. self.sliceLine.setPen((255, 255, 255, 200))
    75. self.sliceLine.setZValue(1)
    76. self.slicePlot.addItem(self.sliceLine)
    77. self.slicePlot.hideAxis('left')
    78.  
    79. self.updateSlicer();
    80.  
    81. self.sliceLine.sigPositionChanged.connect(self.updateSlice)
    82. #print('slice')
    83.  
    84. # Axis Tools
    85. axis_tools_layout = pg.QtGui.QGridLayout()
    86. self.axis_buttons = [];
    87. axesnames = ['x', 'y', 'z'];
    88. for d in range(3):
    89. button = pg.QtGui.QRadioButton(axesnames[d]);
    90. button.setMaximumWidth(50);
    91. axis_tools_layout.addWidget(button,0,d);
    92. button.clicked.connect(ft.partial(self.setSliceAxis, d));
    93. self.axis_buttons.append(button);
    94. self.axis_buttons[self.source_axis].setChecked(True);
    95. axis_tools_widget = pg.QtGui.QWidget();
    96. axis_tools_widget.setLayout(axis_tools_layout);
    97. #print('axis')
    98.  
    99. # coordinate label
    100. self.source_pointer = [0,0,0];
    101. self.source_label = pg.QtGui.QLabel("");
    102. axis_tools_layout.addWidget(self.source_label,0,3);
    103.  
    104. self.graphicsView.scene().sigMouseMoved.connect(self.updateLabelFromMouseMove);
    105. #print('coords')
    106.  
    107. #compose the image viewer
    108. image_splitter.addWidget(self.graphicsView);
    109. image_splitter.addWidget(self.slicePlot)
    110. image_splitter.addWidget(axis_tools_widget);
    111. image_splitter.setSizes([self.height()-35-20, 35, 20])
    112. #print('viewer')
    113.  
    114. # lut widgets
    115. if self.nsources == 1:
    116. cols = ['flame'];
    117. elif self.nsources == 2:
    118. cols = ['purple', 'green'];
    119. else:
    120. cols = np.array(['white', 'green','red', 'blue', 'purple'] * self.nsources)[:self.nsources];
    121.  
    122. self.luts = [LUT(image = i, color = c) for i,c in zip(self.image_items, cols)];
    123.  
    124. lut_layout = pg.QtGui.QGridLayout();
    125.  
    126. lut_layout.setContentsMargins(0,0,0,0);
    127. for d,l in enumerate(self.luts):
    128. lut_layout.addWidget(l,0,d);
    129. lut_widget = pg.QtGui.QWidget();
    130. lut_widget.setLayout(lut_layout);
    131. lut_widget.setContentsMargins(0,0,0,0);
    132. lut_widget.setSizePolicy(pg.QtGui.QSizePolicy.Preferred, pg.QtGui.QSizePolicy.Expanding)
    133. splitter.addWidget(lut_widget);
    134.  
    135. splitter.setStretchFactor(0, 1);
    136. splitter.setStretchFactor(1, 0);
    137.  
    138. # update scale
    139. for l in self.luts:
    140. l.range_buttons[1][2].click();
    141. if minMax is not None:
    142. self.setMinMax(minMax);
    143.  
    144. self.show();
    145. print(pg.QtGui.QApplication.instance())
    To copy to clipboard, switch view to plain text mode 

    What I found out till now:
    • the "allWidget()" function print out all widgets collected by the QApp. and this works finde
    • the code runs till the end (I got a instance pointer at the beginning and in the end; there're the same)
    • I tried several PyQt examples to test for openGL or non openGL Outputs and they all worked fine
    • there's no out-of-memory or CPU overload
    • I tried to cut the code per widget to find the issue, but whatever line of code I commented out no window pops-up anymore
    • I found this great article: https://doc.qt.io/archives/qq/qq27-r...tml#conclusion Could it be something like that?


    Like I said I'm not a programmer and I didn't write the code myself (the author don't answer right now). Its overwhelming but I have to find a solution. Any ideas what I could try next? Anything would be helpful.
    Last edited by SaibotMagd; 7th July 2020 at 17:57.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,564
    Thanks
    255
    Thanked 728 Times in 718 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QApplication Process seems to hang

    All you are showing is a class definition without showing how it is being used. There are a number of dependencies that you are also not giving any details on (ViewBox, GraphcsView, PlotWidget, InfiniteLine). Maybe these are extensions provided by PyQt5 - they aren't part of the standard Qt widget set.

    So a little context would be helpful.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2020
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QApplication Process seems to hang

    The whole code came from: https://github.com/ChristophKirst/ClearMap2. He build a DataViewer to look at tif or numpy converted files.
    The Testcode to check if this class is working is:
    Qt Code:
    1. def _test():
    2. import numpy as np
    3. import ClearMap.Visualization.Qt.DataViewer as dv
    4.  
    5. img1 = np.random.rand(*(100,80,30));
    6.  
    7. dv.DataViewer(img1)
    To copy to clipboard, switch view to plain text mode 
    its in ClearMap/Visualization/Qt/DataViewer.py

    I think it's so basic that it isn't helpful at all. Most interesting part is that the creator and at least 2 others are able to use the Viewer. So the problem shouldn't be in the code itself more about dependencies or the OS. I now try to clone the exact OS he's using. As you see I'm just started using linux and python code, so I don't really know what to do.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,564
    Thanks
    255
    Thanked 728 Times in 718 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QApplication Process seems to hang

    OK, the problem with the test code is that it does not create a QApplication instance, does not call dv.show() (although the __init__ method for DataViewer -does- call it, which it shouldn't). Your test code should look more like this:

    Qt Code:
    1. def _test() :
    2. import sys
    3. from PyQt5.QtWidgets import QApplication
    4. from PyQt5.QtCore import Qt
    5.  
    6. import numpy as np
    7. import ClearMap.Visualization.Qt.DataViewer as dv
    8.  
    9. app = QApplication(sys.argv)
    10.  
    11. img1 = np.random.rand(*(100,80,30));
    12.  
    13. myViewer = dv.DataViewer(img1)
    14.  
    15. myViewer.show()
    16.  
    17. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    The reason the widget works inside a normal application is because the application almost certainly creates the QApplication instance and calls its exec() method so that the normal Qt event loop is up and running and the widget is responding to events. The original _test() method did none of that. Modifying it so it behaves like a mini-standalone app fixes that.
    Last edited by d_stranz; 8th July 2020 at 17:29.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    SaibotMagd (8th July 2020)

  6. #5
    Join Date
    Jul 2020
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Lightbulb Re: QApplication Process seems to hang

    Quote Originally Posted by d_stranz View Post
    OK, the problem with the test code is that it does not create a QApplication instance, does not call dv.show() (although the __init__ method for DataViewer -does- call it, which it shouldn't). Your test code should look more like this:

    The reason the widget works inside a normal application is because the application almost certainly creates the QApplication instance and calls its exec() method so that the normal Qt event loop is up and running and the widget is responding to events. The original _test() method did none of that. Modifying it so it behaves like a mini-standalone app fixes that.
    I barely know what to say, Im in tears. Thats phantastic thank you very very much. It works great and I believe I can implement the solution into the package, and I will do it.

    Great work!

  7. The following user says thank you to SaibotMagd for this useful post:

    d_stranz (9th July 2020)

Similar Threads

  1. The GUI is hang
    By ugiwgh in forum Qt Programming
    Replies: 6
    Last Post: 7th November 2014, 11:04
  2. Using QApplication::processEvents - possible hang under linux
    By SpanishJohn in forum Qt Programming
    Replies: 4
    Last Post: 9th January 2014, 11:43
  3. BlockingQueuedConnection hang
    By ^NyAw^ in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2010, 18:30
  4. How to get the Process ID of my QApplication ?
    By Comer352l in forum Qt Programming
    Replies: 4
    Last Post: 29th November 2008, 10:11
  5. how can I get the QApplication handle by process ID in QT2
    By pencilren in forum Qt Programming
    Replies: 5
    Last Post: 28th August 2007, 20:10

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.