Alpeace
Alpeace

Reputation: 13

Python 3.6; PyQt5; arch linux; interrupted by signal 6: SIGABRT

Intro

I encountered a problem while trying to learn PyQt5.

So far in my search for an answer and understanding to the problem i have come up mostly empty handed. A lot of links and posts i find does not apply to python or even Qt5 at all, which is not strange because SIGABRT applies to several fronts of memory allocation etc. (Correct me if I'm wrong).

I'm fairly certain that the error stems from the lines such as and similar to

buttonEnv.clicked.connect(lambda: self.btnClicked(buttonEnv))

But have not been able to locate or figure out what it is. Probably because of my lack of knowledge coming to python.

System

-OS: Arch linux (Manjaro) 4.9.27-1-MANJARO

-IDE: Pycharm 2017.1

-Python version: 3.6

-Using: PyQt5

Error I'm getting

/usr/bin/python3.6 /opt/pycharm-community/helpers/pydev/pydevd.py --multiproc --qt-support --client 127.0.0.1 --port 42749 --file /home/alpeace/Documents/git_reps/project-tardis/main.py pydev debugger: process 22588 is connecting

Connected to pydev debugger (build 171.4249.47)

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

My code

#!/usr/bin/python3
# -*- coding: utf-8 -*-


import sys
from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication, QGridLayout,\
                            QBoxLayout, QPushButton, QWidget, QSizePolicy
from PyQt5.QtGui import QIcon


class HomeScreen(QWidget):

    clickedBtn = ''

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):

        self.clickedBtn = ''
        homeBtnLayout = QGridLayout()
        self.setLayout(homeBtnLayout)

        buttonEnv = QPushButton('Environment')
        buttonEnv.clicked.connect(lambda: self.btnClicked(buttonEnv))
        buttonEnv.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)

        buttonMedia = QPushButton('Media')
        buttonMedia.clicked.connect(lambda: self.btnClicked(buttonMedia))
        buttonMedia.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)

        buttonInv = QPushButton('Inventory')
        buttonInv.clicked.connect(lambda: self.btnClicked(buttonInv))
        buttonInv.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)

        buttonSched = QPushButton('Schedual')
        buttonSched.clicked.connect(lambda: self.btnClicked(buttonSched))
        buttonSched.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred)

        homeBtnLayout.addWidget(buttonEnv, 0, 0)
        homeBtnLayout.addWidget(buttonMedia, 0, 1)
        homeBtnLayout.addWidget(buttonInv, 1, 0)
        homeBtnLayout.addWidget(buttonSched, 1, 1)

        self.move(300, 150)
        self.show()

    def btnClicked(self, btnName):
        self.clickedBtn = btnName.text()
        btnName.disconnect()

    def getClickedBtn(self):
        return self.clickedBtn


class MainWindow(QMainWindow):

    screenHome = HomeScreen()
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):

        self.setGeometry(300, 300, 300, 250)
        self.setWindowTitle('Home')

        self.screenHome = HomeScreen()
        self.setCentralWidget(self.screenHome)
        self.show()

    def changeWindow(self):

        newWindow = self.screenHome.getClickedBtn()
        if newWindow == 'Environment':
            print(newWindow)
        elif newWindow == 'Media':
            print(newWindow)
        elif newWindow == 'Inventory':
            print(newWindow)
        elif newWindow == 'Schedual':
            print(newWindow)

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = MainWindow()
    sys.exit(app.exec_())

Anyways, thanks for reading and i hope someone might be able to help me with this. If more information is needed i will gladly provide it, but as far as I know this should be sufficient.

Upvotes: 1

Views: 2643

Answers (1)

The Compiler
The Compiler

Reputation: 11969

The problem is you're doing this on class level:

class MainWindow(QMainWindow):

    screenHome = HomeScreen()

This means you're trying to create a HomeScreen at the very beginning, even before your main-block is running.

Since you're assigning self.screenHome properly later anyways:

def initUI(self):
    # [...]
    self.screenHome = HomeScreen()

you can simply get rid of the class level one.

By the way, the faulthandler module is useful in tracking things like this down - when putting an import faulthandler; faulthandler.enable() at the top, Python tells you on what line something happened - in this case it pointed to HomeScreen.__init__ so I've only had to figure out where a HomeScreen object is created before QApplication.

Upvotes: 1

Related Questions