When running code with errors, the console in PyCharm just shows me an exit code with no error

When running code with errors, the console in PyCharm just shows me an exit code with no error.

I tried running the program in cmd and in other ide and they do give me more info such as which file the error occurred in and at what line and etc.

btw, I'm not trying to fix the error. I'm trying to fix the issue with PyCharm not showing me the error in console. Although if I get a solution to the error thats a bonus.

 

In PyCharm console i get:

Process finished with exit code -1073740791 (0xC0000409)

when running the program in cmd i get:

Traceback (most recent call last):
File "main.py", line 98, in <lambda>
self.tabs[i].content.titleChanged.connect(lambda: self.SetTabContent(i, "title"))
File "main.py", line 161, in SetTabContent
if tab_name == tab_data_name["object"]:
TypeError: 'NoneType' object is not subscriptable

 

The code I'm running:

import sys
import os
import json

from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, QHBoxLayout,
QPushButton, QLabel, QLineEdit, QTabBar,
QFrame, QStackedLayout)

from PyQt5.QtGui import QIcon, QWindow, QImage
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *

sys.path.append('/path/to/search')

class AddressBar(QLineEdit):
def __init__(self):
super().__init__()


def mousePressEvent(self, e):
self.selectAll()

class App(QFrame):
def __init__(self):
super().__init__()
self.setWindowTitle("Web Browser")
self.CreateApp()
self.resize(1366, 768)

def CreateApp(self):
self.layout = QVBoxLayout()
self.layout.setSpacing(0)
self.layout.setContentsMargins(0, 0, 0, 0)

# Create Tabs
self.tabbar = QTabBar(movable=True, tabsClosable=True)
self.tabbar.tabCloseRequested.connect(self.CloseTab)
self.tabbar.tabBarClicked.connect(self.SwitchTab)
self.tabbar.setDrawBase(False)

self.tabbar.setCurrentIndex(0)

# Keep track of tabs
self.tabCount = 0
self.tabs = []

# Create AddressBar
self.Toolbar = QWidget()
self.ToolbarLayout = QHBoxLayout()
self.addressbar = AddressBar()

# Connect AddressBar + button Signals
self.addressbar.returnPressed.connect(self.BrowseTo)

# Build toolbar
self.Toolbar.setLayout(self.ToolbarLayout)
self.ToolbarLayout.addWidget(self.addressbar)

# New tab button
self.AddTabButton = QPushButton("+")
self.AddTabButton.clicked.connect(self.AddTab)

self.ToolbarLayout.addWidget(self.AddTabButton)

# Set main view
self.container = QWidget()
self.container.layout = QStackedLayout()
self.container.setLayout(self.container.layout)

# Construct main view from top level elements
self.layout.addWidget(self.tabbar)
self.layout.addWidget(self.Toolbar)
self.layout.addWidget(self.container)
self.setLayout(self.layout)

self.AddTab()

self.show()

def CloseTab(self, i):
self.tabbar.removeTab(i)

def AddTab(self):
i = self.tabCount

# Set self.tabs<#> = QWidget
self.tabs.append(QWidget())
self.tabs[i].layout = QVBoxLayout()
self.tabs[i].layout.setContentsMargins(0, 0, 0, 0)

# For tab switching
self.tabs[i].setObjectName("tab" + str(i))

# Create webview within the tabs top level widget
self.tabs[i].content = QWebEngineView()
self.tabs[i].content.load(QUrl.fromUserInput("http://google.com"))

self.tabs[i].content.titleChanged.connect(lambda: self.SetTabContent(i, "title"))
self.tabs[i].content.iconChanged.connect(lambda: self.SetTabContent(i, "icon"))

# Add webview to tabs layout
self.tabs[i].layout.addWidget(self.tabs[i].content)

# set top level tab from [] to layout
self.tabs[i].setLayout(self.tabs[i].layout)

# Add tab to top level stackedwidget
self.container.layout.addWidget(self.tabs[i])
self.container.layout.setCurrentWidget(self.tabs[i])

# Set the tab at top of screen
# Create tab on tabbar, representing this tab
# Set tabData to tab<#> So it knows what self.tabs[#] it needs to control
self.tabbar.addTab("New Tab")
#self.tabbar.setTabData(i, "tab" + str(i))
self.tabbar.setTabData(i, {"object": "tab" + str(i), "initial": i})



self.tabbar.setCurrentIndex(i)

self.tabCount += 1

def SwitchTab(self, i):
tab_data = self.tabbar.tabData(i)["object"]
print("tab:", tab_data)

tab_content = self.findChild(QWidget, tab_data)
self.container.layout.setCurrentWidget(tab_content)

def BrowseTo(self):
text = self.addressbar.text()
print(text)

i = self.tabbar.currentIndex()
tab = self.tabbar.tabData(i)["object"]
web_view = self.findChild(QWidget, tab).content

if "http" not in text:
if "." not in text:
url = "https://www.google.com/search?q=" + text
else:
url = "http://" + text
else:
url = text

web_view.load(QUrl.fromUserInput(url))

def SetTabContent(self, i, type):
tab_name = self.tabs[i].objectName()

count = 0
running = True

while running:
tab_data_name = self.tabbar.tabData(count)

if count >= 99:
running = False

if tab_name == tab_data_name["object"]:
if type == "title":
newTitle = self.findChild(QWidget, tab_name).content.title()
self.tabbar.setTabText(count, newTitle)
elif type == "icon":
newIcon = self.findChild(QWidget, tab_name).content.icon()
self.tabbar.setTabIcon(count, newIcon)

running = False
else:
print(count)
count += 1


if __name__ == "__main__":
app = QApplication(sys.argv)
window = App()
sys.exit(app.exec_())

 

The error/crash is produced when I open a tab after closing a previous tab

 

0

Hi, what's your OS, are you on Windows? Are you sure that you're using the same interpreter when running in PyCharm vs terminal? 

0xc0000409 seems to be a Windows-specific error: https://answers.microsoft.com/en-us/windows/forum/windows_10-windows_install/error-code-0xc0000409/228538ba-75f6-4dd1-a6bb-0d5ed718f3e3

0

I guess that this is largely the same case as discussed here: https://stackoverflow.com/a/33741755/1032586

0

请先登录再写评论。