-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyQt 5 issue in spyder #4639
Comments
@dalthviz, what was the solution to this problem? |
Hello, well actually didn't found it.... it's still an issue. It works one out of 2 times and cannot compile it neither. I get this message : C:\Users\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D. An exception has occurred, use %tb to see the full traceback. SystemExit: -1 |
Yeah, @dalthviz knows the solution to this (it's very simple indeed), so please wait until he chimes in. |
Thanks so much! I'll wait then! |
Hi @dalthviz I tried but the error persists :( |
@ciornav could you submit your |
Hello, thanks for helping out with this. Apparently the .ui files are not supported in this chat. I struggle to get teh files uploaded to my github profile... guess need to look into uploading for doing it properly.... |
You could maybe copy paste the xml code here? |
ok so found it.... https://github.com/ciornav/files_to_test I"ve put teh .ui and .py there. |
/******************************************************************************** #ifndef VSCP49940_H #include <QtCore/QVariant> QT_BEGIN_NAMESPACE class Ui_MainWindow
}; namespace Ui { QT_END_NAMESPACE #endif // VSCP49940_H |
@ciornav what happens if instead of |
Thank you so much.... it works!!!!! |
I've had an issue with the same isuue. Is apparently it is a standard bug running PyQt applications. Is there a way about informing the user about this behavior? It should save some time for relevant users if it was mentioned in the docs for example. Edit:
Within my main the program crashes. This is also due the Spyder Qt behaviour. How to handle the quitting of the app using Spyder? |
Hi @Jeroendevr testing a little bit, try to make a function for the creation of the QApplication instance (to make it local and prevent it to get in the namespace of the kernel of the console), as an example (based on this): import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize
class HelloWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(100, 100))
self.setWindowTitle("Hello world")
centralWidget = QWidget(self)
self.setCentralWidget(centralWidget)
gridLayout = QGridLayout(self)
centralWidget.setLayout(gridLayout)
title = QLabel("Hello World from PyQt", self)
title.setAlignment(QtCore.Qt.AlignCenter)
gridLayout.addWidget(title, 0, 0)
menu = self.menuBar().addMenu('Action for quit')
action = menu.addAction('Quit')
action.triggered.connect(QtWidgets.QApplication.quit)
if __name__ == "__main__":
def run_app():
app = QtWidgets.QApplication(sys.argv)
mainWin = HelloWindow()
mainWin.show()
app.exec_()
run_app() Then most of the problems of running a QApplication multiple times inside Spyder is that a QApplication instance remains in the namespace of the kernel of the IPython console after the first run, then when you try to re-run your application you already have a QApplication instance initialized. Trying to quit a QApplication instance that you have a reference, in your case, is probably causing your program to get stuck in the blocking while-loop as suggested here, and here using |
So is it a IPython problem then instead of an Qt-Spyder problem? There was a issue for this at the IPython repo if I recall correctly. Any update on that subject? |
Hi @Jeroendevr in #4349 there was a proposal to monkeypatch |
@dalthviz your code solved the problem; however, after I made that change there is another warning showed up Do you have any idea why this warning rise ? |
Hi @Omar-Aboelsoud probably you are reimporting does modules when running your application. Maybe #2325 could give you some guidance to prevent the warning :) |
So I was still having problems with my application not exiting, even with the suggestions given in this thread. My current understanding of the problem is that the QtWidget.QtApplication object has a flag 'quitOnLastWindowClosed' that is by default set to False. This can be set to true by calling:
somewhere before you call qapp.exec_(). Note that this is a static method. If the above doesn't work for some reason, I also found adding an overridden closeEvent function to the 'HelloWindow' class that calls QtWidgets.QApplication.quit() also works (taking inspiration from @dalthviz 's quit menu button).
|
based on what you said, I added: QtWidgets.QApplication.setQuitOnLastWindowClosed(True) before app.exec(), working code as follows, though have some typos in your solution, but this is the only workable solution this problem for me, I really appreciate, if this problem have not been resolved, I would lose my faith of continuing python studying as a beginner, thanks @gigo318 if name == "main": |
This problem was fixed in our 4.1.1 version. Please update. |
thanks, I tried to conda upgrade spyder, but it says constrained by anaconda, I am concerned that anaconda won't work if I upgraded to 4.1.1, do u have any idea about this? sorry, I am quite new to python |
Please run
|
Description of your problem
The run of a .ui file in spyder using PyQt 5 gives an error message every 2 times I run the .py file.
What steps will reproduce the problem?
What is the expected output? What do you see instead?
I would like to see the GUI and use the functionalities that I've coded in the .py file.
Please provide any additional information below
The code I have in the .py file is the following (guess the error comes somewhere from here):
Versions and main components
Dependencies
Please go to the menu entry
Help > Optional Dependencies
(orHelp > Dependencies
), press the buttonCopy to clipboard
and paste the contents below:
jedi >=0.8.1 : 0.9.0 (OK)
matplotlib >=1.0 : 2.0.0 (OK)
nbconvert >=4.0 : 4.2.0 (OK)
numpy >=1.7 : 1.12.1 (OK)
pandas >=0.13.1 : 0.19.2 (OK)
pep8 >=0.6 : 1.7.0 (OK)
pyflakes >=0.6.0 : 1.5.0 (OK)
pygments >=2.0 : 2.1.3 (OK)
pylint >=0.25 : 1.6.4 (OK)
qtconsole >=4.2.0: 4.2.1 (OK)
rope >=0.9.4 : 0.9.4-1 (OK)
sphinx >=0.6.6 : 1.5.1 (OK)
sympy >=0.7.3 : 1.0 (OK)
The text was updated successfully, but these errors were encountered: