gui not responding during process?











up vote
1
down vote

favorite












I have sql query. My push button connects with sql - it takes long time. During it, my GUI is not responding - is it possible to make it responds?



QtCore.QCoreApplication.processEvents() doesnt work.



QApp.py



# -- coding: utf-8 --

from PyQt5 import QtGui, QtWidgets, QtCore
import qdarkstyle
import pyodbc

class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow,self).__init__(parent)

self.main_frame()
self.center() #center frame
self.layout_init() #widgets layout

def main_frame(self):
### actions on meenubar
exitAct = QtWidgets.QAction('&Exit', self)
exitAct.setShortcut('Ctrl+Q')
exitAct.setStatusTip('Exit application')
exitAct.triggered.connect(self.close)
self.statusBar()

moreinfo = QtWidgets.QAction('&Help',self)
moreinfo.setStatusTip('More information')
moreinfo.triggered.connect(self.information)
self.statusBar()

### menubar
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(exitAct)
fileMenu = menubar.addMenu('&Help')
fileMenu.addAction(moreinfo)


### basic geometry and color
self.setWindowTitle('Villain')
self.setWindowIcon(QtGui.QIcon('dc1.png'))
self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


def layout_init(self):
self.grid = QtWidgets.QGridLayout()
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)

### widgets
self.tablewidget = QtWidgets.QTableWidget()
self.tablewidget.setColumnCount(4)
self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
self.tablewidget.horizontalHeader().setStretchLastSection(True)
self.tablewidget.resizeColumnsToContents()
self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
#self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

self.textbox = QtWidgets.QLineEdit()
self.textbox.setPlaceholderText('IMEI')
self.textbox.setEnabled(True)
regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

self.pb = QtWidgets.QPushButton(self.tr("Run process"))
self.pb.setDisabled(True)
self.textbox.textChanged.connect(self.disableButton)
self.pb.clicked.connect(self.on_clicked_pb)


self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
self.clearbutton.setDisabled(True)
self.clearbutton.clicked.connect(self.on_clicked_clear)

### make vidgets alive
self.centralWidget().setLayout(self.grid)
self.grid.addWidget(self.textbox)
self.grid.addWidget(self.tablewidget)
self.grid.addWidget(self.pb)
self.grid.addWidget(self.clearbutton)


### center main window
def center(self):
qr = self.frameGeometry()
cp = QtWidgets.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())



def information(self):
QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
'This is the prototype of the applicationnn'
'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
'Digital Care - Data Processing Team')

def disableButton(self):
if len(self.textbox.text())> 0:
self.pb.setDisabled(False)
self.clearbutton.setDisabled(False)
else:
self.pb.setDisabled(True)
self.clearbutton.setDisabled(True)


### run process button
@QtCore.pyqtSlot()
def on_clicked_pb(self):
if len(self.textbox.text()) == 0:
pass
else:
self.sql_query()


### clear all
@QtCore.pyqtSlot()
def on_clicked_clear(self):
if len(self.textbox.text())> 0:
self.textbox.clear()
self.tablewidget.setRowCount(0)
self.tablewidget.setColumnWidth(3, 200)

def setCredentials(self, credentials):
self._credentials = credentials

def sql_query(self):
ser = "10.96.6.14"
base = "PROD_WAREX2"
username, pwd = self._credentials

QtCore.QCoreApplication.processEvents()
try:
self.connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
user=username, password=pwd)
cursor = self.connection.cursor()
self.res = cursor.execute(""" SELECT FI.FileNameTransformed,
FI.OrderItemCode,
FIR.Imported,
FR.Row
FROM [FileRows] AS FR
JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
if not cursor.rowcount:
QtWidgets.QMessageBox.information(self, 'IMEI', "No items found")
cursor.close()
pass
else:
self.tablewidget.setRowCount(0)
for row, form in enumerate(self.res):
self.tablewidget.insertRow(row)
for column, item in enumerate(form):
newitem = QtWidgets.QTableWidgetItem(str(item))
self.tablewidget.setItem(row, column, newitem)
cursor.close()
self.table_performance()
self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)
except:
QtWidgets.QMessageBox.warning(self, 'Error', "Something went wrongnn"
"Contact karol.chojnowski@digitalcaregroup.com")
QtWidgets.QMessageBox.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


def table_performance(self):
self.tablewidget.resizeColumnsToContents()
self.tablewidget.setColumnWidth(3, 2500)
self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)


main .py:



Villain.py



# -- coding: utf-8 --

import sys
from PyQt5 import QtWidgets,QtGui
from QLogin import LoginDialog
from QApp import MainWindow
import os


def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)


if __name__ == '__main__':

app = QtWidgets.QApplication(sys.argv)

login = LoginDialog()
login.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))

if login.exec_() != QtWidgets.QDialog.Accepted:
sys.exit(-1)

window = MainWindow()
window.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))
window.setGeometry(500, 150, 800, 500)
window.setCredentials(login.credentials()) # <----
window.show()
sys.exit(app.exec_())









share|improve this question




























    up vote
    1
    down vote

    favorite












    I have sql query. My push button connects with sql - it takes long time. During it, my GUI is not responding - is it possible to make it responds?



    QtCore.QCoreApplication.processEvents() doesnt work.



    QApp.py



    # -- coding: utf-8 --

    from PyQt5 import QtGui, QtWidgets, QtCore
    import qdarkstyle
    import pyodbc

    class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
    super(MainWindow,self).__init__(parent)

    self.main_frame()
    self.center() #center frame
    self.layout_init() #widgets layout

    def main_frame(self):
    ### actions on meenubar
    exitAct = QtWidgets.QAction('&Exit', self)
    exitAct.setShortcut('Ctrl+Q')
    exitAct.setStatusTip('Exit application')
    exitAct.triggered.connect(self.close)
    self.statusBar()

    moreinfo = QtWidgets.QAction('&Help',self)
    moreinfo.setStatusTip('More information')
    moreinfo.triggered.connect(self.information)
    self.statusBar()

    ### menubar
    menubar = self.menuBar()
    fileMenu = menubar.addMenu('&File')
    fileMenu.addAction(exitAct)
    fileMenu = menubar.addMenu('&Help')
    fileMenu.addAction(moreinfo)


    ### basic geometry and color
    self.setWindowTitle('Villain')
    self.setWindowIcon(QtGui.QIcon('dc1.png'))
    self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


    def layout_init(self):
    self.grid = QtWidgets.QGridLayout()
    central_widget = QtWidgets.QWidget()
    self.setCentralWidget(central_widget)

    ### widgets
    self.tablewidget = QtWidgets.QTableWidget()
    self.tablewidget.setColumnCount(4)
    self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
    self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
    self.tablewidget.horizontalHeader().setStretchLastSection(True)
    self.tablewidget.resizeColumnsToContents()
    self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
    self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
    #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

    self.textbox = QtWidgets.QLineEdit()
    self.textbox.setPlaceholderText('IMEI')
    self.textbox.setEnabled(True)
    regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
    self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

    self.pb = QtWidgets.QPushButton(self.tr("Run process"))
    self.pb.setDisabled(True)
    self.textbox.textChanged.connect(self.disableButton)
    self.pb.clicked.connect(self.on_clicked_pb)


    self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
    self.clearbutton.setDisabled(True)
    self.clearbutton.clicked.connect(self.on_clicked_clear)

    ### make vidgets alive
    self.centralWidget().setLayout(self.grid)
    self.grid.addWidget(self.textbox)
    self.grid.addWidget(self.tablewidget)
    self.grid.addWidget(self.pb)
    self.grid.addWidget(self.clearbutton)


    ### center main window
    def center(self):
    qr = self.frameGeometry()
    cp = QtWidgets.QDesktopWidget().availableGeometry().center()
    qr.moveCenter(cp)
    self.move(qr.topLeft())



    def information(self):
    QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
    'This is the prototype of the applicationnn'
    'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
    'Digital Care - Data Processing Team')

    def disableButton(self):
    if len(self.textbox.text())> 0:
    self.pb.setDisabled(False)
    self.clearbutton.setDisabled(False)
    else:
    self.pb.setDisabled(True)
    self.clearbutton.setDisabled(True)


    ### run process button
    @QtCore.pyqtSlot()
    def on_clicked_pb(self):
    if len(self.textbox.text()) == 0:
    pass
    else:
    self.sql_query()


    ### clear all
    @QtCore.pyqtSlot()
    def on_clicked_clear(self):
    if len(self.textbox.text())> 0:
    self.textbox.clear()
    self.tablewidget.setRowCount(0)
    self.tablewidget.setColumnWidth(3, 200)

    def setCredentials(self, credentials):
    self._credentials = credentials

    def sql_query(self):
    ser = "10.96.6.14"
    base = "PROD_WAREX2"
    username, pwd = self._credentials

    QtCore.QCoreApplication.processEvents()
    try:
    self.connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
    user=username, password=pwd)
    cursor = self.connection.cursor()
    self.res = cursor.execute(""" SELECT FI.FileNameTransformed,
    FI.OrderItemCode,
    FIR.Imported,
    FR.Row
    FROM [FileRows] AS FR
    JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
    JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
    WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
    if not cursor.rowcount:
    QtWidgets.QMessageBox.information(self, 'IMEI', "No items found")
    cursor.close()
    pass
    else:
    self.tablewidget.setRowCount(0)
    for row, form in enumerate(self.res):
    self.tablewidget.insertRow(row)
    for column, item in enumerate(form):
    newitem = QtWidgets.QTableWidgetItem(str(item))
    self.tablewidget.setItem(row, column, newitem)
    cursor.close()
    self.table_performance()
    self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)
    except:
    QtWidgets.QMessageBox.warning(self, 'Error', "Something went wrongnn"
    "Contact karol.chojnowski@digitalcaregroup.com")
    QtWidgets.QMessageBox.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


    def table_performance(self):
    self.tablewidget.resizeColumnsToContents()
    self.tablewidget.setColumnWidth(3, 2500)
    self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)


    main .py:



    Villain.py



    # -- coding: utf-8 --

    import sys
    from PyQt5 import QtWidgets,QtGui
    from QLogin import LoginDialog
    from QApp import MainWindow
    import os


    def resource_path(relative_path):
    if hasattr(sys, '_MEIPASS'):
    return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(os.path.abspath("."), relative_path)


    if __name__ == '__main__':

    app = QtWidgets.QApplication(sys.argv)

    login = LoginDialog()
    login.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))

    if login.exec_() != QtWidgets.QDialog.Accepted:
    sys.exit(-1)

    window = MainWindow()
    window.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))
    window.setGeometry(500, 150, 800, 500)
    window.setCredentials(login.credentials()) # <----
    window.show()
    sys.exit(app.exec_())









    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have sql query. My push button connects with sql - it takes long time. During it, my GUI is not responding - is it possible to make it responds?



      QtCore.QCoreApplication.processEvents() doesnt work.



      QApp.py



      # -- coding: utf-8 --

      from PyQt5 import QtGui, QtWidgets, QtCore
      import qdarkstyle
      import pyodbc

      class MainWindow(QtWidgets.QMainWindow):
      def __init__(self, parent=None):
      super(MainWindow,self).__init__(parent)

      self.main_frame()
      self.center() #center frame
      self.layout_init() #widgets layout

      def main_frame(self):
      ### actions on meenubar
      exitAct = QtWidgets.QAction('&Exit', self)
      exitAct.setShortcut('Ctrl+Q')
      exitAct.setStatusTip('Exit application')
      exitAct.triggered.connect(self.close)
      self.statusBar()

      moreinfo = QtWidgets.QAction('&Help',self)
      moreinfo.setStatusTip('More information')
      moreinfo.triggered.connect(self.information)
      self.statusBar()

      ### menubar
      menubar = self.menuBar()
      fileMenu = menubar.addMenu('&File')
      fileMenu.addAction(exitAct)
      fileMenu = menubar.addMenu('&Help')
      fileMenu.addAction(moreinfo)


      ### basic geometry and color
      self.setWindowTitle('Villain')
      self.setWindowIcon(QtGui.QIcon('dc1.png'))
      self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


      def layout_init(self):
      self.grid = QtWidgets.QGridLayout()
      central_widget = QtWidgets.QWidget()
      self.setCentralWidget(central_widget)

      ### widgets
      self.tablewidget = QtWidgets.QTableWidget()
      self.tablewidget.setColumnCount(4)
      self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
      self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
      self.tablewidget.horizontalHeader().setStretchLastSection(True)
      self.tablewidget.resizeColumnsToContents()
      self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
      self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
      #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

      self.textbox = QtWidgets.QLineEdit()
      self.textbox.setPlaceholderText('IMEI')
      self.textbox.setEnabled(True)
      regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
      self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

      self.pb = QtWidgets.QPushButton(self.tr("Run process"))
      self.pb.setDisabled(True)
      self.textbox.textChanged.connect(self.disableButton)
      self.pb.clicked.connect(self.on_clicked_pb)


      self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
      self.clearbutton.setDisabled(True)
      self.clearbutton.clicked.connect(self.on_clicked_clear)

      ### make vidgets alive
      self.centralWidget().setLayout(self.grid)
      self.grid.addWidget(self.textbox)
      self.grid.addWidget(self.tablewidget)
      self.grid.addWidget(self.pb)
      self.grid.addWidget(self.clearbutton)


      ### center main window
      def center(self):
      qr = self.frameGeometry()
      cp = QtWidgets.QDesktopWidget().availableGeometry().center()
      qr.moveCenter(cp)
      self.move(qr.topLeft())



      def information(self):
      QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
      'This is the prototype of the applicationnn'
      'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
      'Digital Care - Data Processing Team')

      def disableButton(self):
      if len(self.textbox.text())> 0:
      self.pb.setDisabled(False)
      self.clearbutton.setDisabled(False)
      else:
      self.pb.setDisabled(True)
      self.clearbutton.setDisabled(True)


      ### run process button
      @QtCore.pyqtSlot()
      def on_clicked_pb(self):
      if len(self.textbox.text()) == 0:
      pass
      else:
      self.sql_query()


      ### clear all
      @QtCore.pyqtSlot()
      def on_clicked_clear(self):
      if len(self.textbox.text())> 0:
      self.textbox.clear()
      self.tablewidget.setRowCount(0)
      self.tablewidget.setColumnWidth(3, 200)

      def setCredentials(self, credentials):
      self._credentials = credentials

      def sql_query(self):
      ser = "10.96.6.14"
      base = "PROD_WAREX2"
      username, pwd = self._credentials

      QtCore.QCoreApplication.processEvents()
      try:
      self.connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
      user=username, password=pwd)
      cursor = self.connection.cursor()
      self.res = cursor.execute(""" SELECT FI.FileNameTransformed,
      FI.OrderItemCode,
      FIR.Imported,
      FR.Row
      FROM [FileRows] AS FR
      JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
      JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
      WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
      if not cursor.rowcount:
      QtWidgets.QMessageBox.information(self, 'IMEI', "No items found")
      cursor.close()
      pass
      else:
      self.tablewidget.setRowCount(0)
      for row, form in enumerate(self.res):
      self.tablewidget.insertRow(row)
      for column, item in enumerate(form):
      newitem = QtWidgets.QTableWidgetItem(str(item))
      self.tablewidget.setItem(row, column, newitem)
      cursor.close()
      self.table_performance()
      self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)
      except:
      QtWidgets.QMessageBox.warning(self, 'Error', "Something went wrongnn"
      "Contact karol.chojnowski@digitalcaregroup.com")
      QtWidgets.QMessageBox.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


      def table_performance(self):
      self.tablewidget.resizeColumnsToContents()
      self.tablewidget.setColumnWidth(3, 2500)
      self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)


      main .py:



      Villain.py



      # -- coding: utf-8 --

      import sys
      from PyQt5 import QtWidgets,QtGui
      from QLogin import LoginDialog
      from QApp import MainWindow
      import os


      def resource_path(relative_path):
      if hasattr(sys, '_MEIPASS'):
      return os.path.join(sys._MEIPASS, relative_path)
      return os.path.join(os.path.abspath("."), relative_path)


      if __name__ == '__main__':

      app = QtWidgets.QApplication(sys.argv)

      login = LoginDialog()
      login.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))

      if login.exec_() != QtWidgets.QDialog.Accepted:
      sys.exit(-1)

      window = MainWindow()
      window.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))
      window.setGeometry(500, 150, 800, 500)
      window.setCredentials(login.credentials()) # <----
      window.show()
      sys.exit(app.exec_())









      share|improve this question















      I have sql query. My push button connects with sql - it takes long time. During it, my GUI is not responding - is it possible to make it responds?



      QtCore.QCoreApplication.processEvents() doesnt work.



      QApp.py



      # -- coding: utf-8 --

      from PyQt5 import QtGui, QtWidgets, QtCore
      import qdarkstyle
      import pyodbc

      class MainWindow(QtWidgets.QMainWindow):
      def __init__(self, parent=None):
      super(MainWindow,self).__init__(parent)

      self.main_frame()
      self.center() #center frame
      self.layout_init() #widgets layout

      def main_frame(self):
      ### actions on meenubar
      exitAct = QtWidgets.QAction('&Exit', self)
      exitAct.setShortcut('Ctrl+Q')
      exitAct.setStatusTip('Exit application')
      exitAct.triggered.connect(self.close)
      self.statusBar()

      moreinfo = QtWidgets.QAction('&Help',self)
      moreinfo.setStatusTip('More information')
      moreinfo.triggered.connect(self.information)
      self.statusBar()

      ### menubar
      menubar = self.menuBar()
      fileMenu = menubar.addMenu('&File')
      fileMenu.addAction(exitAct)
      fileMenu = menubar.addMenu('&Help')
      fileMenu.addAction(moreinfo)


      ### basic geometry and color
      self.setWindowTitle('Villain')
      self.setWindowIcon(QtGui.QIcon('dc1.png'))
      self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


      def layout_init(self):
      self.grid = QtWidgets.QGridLayout()
      central_widget = QtWidgets.QWidget()
      self.setCentralWidget(central_widget)

      ### widgets
      self.tablewidget = QtWidgets.QTableWidget()
      self.tablewidget.setColumnCount(4)
      self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
      self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
      self.tablewidget.horizontalHeader().setStretchLastSection(True)
      self.tablewidget.resizeColumnsToContents()
      self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
      self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
      #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

      self.textbox = QtWidgets.QLineEdit()
      self.textbox.setPlaceholderText('IMEI')
      self.textbox.setEnabled(True)
      regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
      self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

      self.pb = QtWidgets.QPushButton(self.tr("Run process"))
      self.pb.setDisabled(True)
      self.textbox.textChanged.connect(self.disableButton)
      self.pb.clicked.connect(self.on_clicked_pb)


      self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
      self.clearbutton.setDisabled(True)
      self.clearbutton.clicked.connect(self.on_clicked_clear)

      ### make vidgets alive
      self.centralWidget().setLayout(self.grid)
      self.grid.addWidget(self.textbox)
      self.grid.addWidget(self.tablewidget)
      self.grid.addWidget(self.pb)
      self.grid.addWidget(self.clearbutton)


      ### center main window
      def center(self):
      qr = self.frameGeometry()
      cp = QtWidgets.QDesktopWidget().availableGeometry().center()
      qr.moveCenter(cp)
      self.move(qr.topLeft())



      def information(self):
      QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
      'This is the prototype of the applicationnn'
      'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
      'Digital Care - Data Processing Team')

      def disableButton(self):
      if len(self.textbox.text())> 0:
      self.pb.setDisabled(False)
      self.clearbutton.setDisabled(False)
      else:
      self.pb.setDisabled(True)
      self.clearbutton.setDisabled(True)


      ### run process button
      @QtCore.pyqtSlot()
      def on_clicked_pb(self):
      if len(self.textbox.text()) == 0:
      pass
      else:
      self.sql_query()


      ### clear all
      @QtCore.pyqtSlot()
      def on_clicked_clear(self):
      if len(self.textbox.text())> 0:
      self.textbox.clear()
      self.tablewidget.setRowCount(0)
      self.tablewidget.setColumnWidth(3, 200)

      def setCredentials(self, credentials):
      self._credentials = credentials

      def sql_query(self):
      ser = "10.96.6.14"
      base = "PROD_WAREX2"
      username, pwd = self._credentials

      QtCore.QCoreApplication.processEvents()
      try:
      self.connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
      user=username, password=pwd)
      cursor = self.connection.cursor()
      self.res = cursor.execute(""" SELECT FI.FileNameTransformed,
      FI.OrderItemCode,
      FIR.Imported,
      FR.Row
      FROM [FileRows] AS FR
      JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
      JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
      WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
      if not cursor.rowcount:
      QtWidgets.QMessageBox.information(self, 'IMEI', "No items found")
      cursor.close()
      pass
      else:
      self.tablewidget.setRowCount(0)
      for row, form in enumerate(self.res):
      self.tablewidget.insertRow(row)
      for column, item in enumerate(form):
      newitem = QtWidgets.QTableWidgetItem(str(item))
      self.tablewidget.setItem(row, column, newitem)
      cursor.close()
      self.table_performance()
      self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)
      except:
      QtWidgets.QMessageBox.warning(self, 'Error', "Something went wrongnn"
      "Contact karol.chojnowski@digitalcaregroup.com")
      QtWidgets.QMessageBox.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))


      def table_performance(self):
      self.tablewidget.resizeColumnsToContents()
      self.tablewidget.setColumnWidth(3, 2500)
      self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)


      main .py:



      Villain.py



      # -- coding: utf-8 --

      import sys
      from PyQt5 import QtWidgets,QtGui
      from QLogin import LoginDialog
      from QApp import MainWindow
      import os


      def resource_path(relative_path):
      if hasattr(sys, '_MEIPASS'):
      return os.path.join(sys._MEIPASS, relative_path)
      return os.path.join(os.path.abspath("."), relative_path)


      if __name__ == '__main__':

      app = QtWidgets.QApplication(sys.argv)

      login = LoginDialog()
      login.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))

      if login.exec_() != QtWidgets.QDialog.Accepted:
      sys.exit(-1)

      window = MainWindow()
      window.setWindowIcon(QtGui.QIcon(resource_path('dc1.png')))
      window.setGeometry(500, 150, 800, 500)
      window.setCredentials(login.credentials()) # <----
      window.show()
      sys.exit(app.exec_())






      python python-3.x pyqt pyqt5 qtablewidget






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 17:34









      eyllanesc

      71.3k93053




      71.3k93053










      asked Nov 20 at 10:20









      Karol357

      286




      286
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The use of processEvents() implies in most cases a bad design. If you have a heavy task, do not execute it in the main thread, execute it in another thread and send the necessary data to the main thread by means of signals or with QMetaObject::invokeMethod() (this last option will be used since it is not necessary so much connection).



          On the other hand you should only add the stylesheet once, if there are new widgets they will take as a basis the stylesheet.



          # -- coding: utf-8 --
          import threading
          from PyQt5 import QtGui, QtWidgets, QtCore
          import qdarkstyle
          import pyodbc

          class MainWindow(QtWidgets.QMainWindow):
          def __init__(self, parent=None):
          super(MainWindow,self).__init__(parent)

          self.main_frame()
          self.center() #center frame
          self.layout_init() #widgets layout

          def main_frame(self):
          ### actions on meenubar
          exitAct = QtWidgets.QAction('&Exit', self, shortcut='Ctrl+Q', statusTip='application')
          exitAct.triggered.connect(self.close)

          moreinfo = QtWidgets.QAction('&Help',self, statusTip='More information')
          moreinfo.triggered.connect(self.information)

          ### menubar
          menubar = self.menuBar()
          fileMenu = menubar.addMenu('&File')
          fileMenu.addAction(exitAct)
          fileMenu = menubar.addMenu('&Help')
          fileMenu.addAction(moreinfo)

          ### basic geometry and color
          self.setWindowTitle('Villain')
          self.setWindowIcon(QtGui.QIcon('dc1.png'))
          self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))

          def layout_init(self):
          central_widget = QtWidgets.QWidget()
          self.setCentralWidget(central_widget)

          ### widgets
          self.tablewidget = QtWidgets.QTableWidget()
          self.tablewidget.setColumnCount(4)
          self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
          self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
          self.tablewidget.horizontalHeader().setStretchLastSection(True)
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
          self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
          #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

          self.textbox = QtWidgets.QLineEdit()
          self.textbox.setPlaceholderText('IMEI')
          self.textbox.setEnabled(True)
          regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
          self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

          self.pb = QtWidgets.QPushButton(self.tr("Run process"))
          self.pb.setDisabled(True)
          self.textbox.textChanged.connect(self.disableButton)
          self.pb.clicked.connect(self.on_clicked_pb)

          self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
          self.clearbutton.setDisabled(True)
          self.clearbutton.clicked.connect(self.on_clicked_clear)

          ### make vidgets alive
          grid = QtWidgets.QGridLayout(central_widget)
          grid.addWidget(self.textbox)
          grid.addWidget(self.tablewidget)
          grid.addWidget(self.pb)
          grid.addWidget(self.clearbutton)

          self.table_performance()

          ### center main window
          def center(self):
          qr = self.frameGeometry()
          cp = QtWidgets.QDesktopWidget().availableGeometry().center()
          qr.moveCenter(cp)
          self.move(qr.topLeft())

          def information(self):
          QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
          'This is the prototype of the applicationnn'
          'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
          'Digital Care - Data Processing Team')


          @QtCore.pyqtSlot()
          def disableButton(self):
          val = bool(self.textbox.text())
          self.pb.setDisabled(not val)
          self.clearbutton.setDisabled(not val)

          ### run process button
          @QtCore.pyqtSlot()
          def on_clicked_pb(self):
          if self.textbox.text():
          threading.Thread(target=self.sql_query, daemon=True).start()
          ### clear all
          @QtCore.pyqtSlot()
          def on_clicked_clear(self):
          if self.textbox.text():
          self.textbox.clear()
          self.tablewidget.setRowCount(0)
          self.tablewidget.setColumnWidth(3, 200)

          def setCredentials(self, credentials):
          self._credentials = credentials

          def table_performance(self):
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setColumnWidth(3, 2500)
          self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)

          @QtCore.pyqtSlot(str, str)
          def show_warning(self, title, msg):
          QtWidgets.QMessageBox.information(self, title, msg)

          @QtCore.pyqtSlot()
          def clear_items(self):
          self.tablewidget.setRowCount(0)

          @QtCore.pyqtSlot(int, int, str)
          def add_item(self, row, column, val):
          if row >= self.tablewidget.rowCount():
          self.tablewidget.insertRow(self.tablewidget.rowCount())
          newitem = QtWidgets.QTableWidgetItem(val)
          self.tablewidget.setItem(row, column, newitem)

          @QtCore.pyqtSlot()
          def sort_items(self):
          self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)

          def sql_query(self):
          ser = "10.96.6.14"
          base = "PROD_WAREX2"
          username, pwd = self._credentials
          try:
          connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
          user=username, password=pwd)
          cursor = connection.cursor()
          res = cursor.execute(""" SELECT FI.FileNameTransformed,
          FI.OrderItemCode,
          FIR.Imported,
          FR.Row
          FROM [FileRows] AS FR
          JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
          JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
          WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
          if not cursor.rowcount:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found"))
          else:
          QtCore.QMetaObject.invokeMethod(self, "clear_items", QtCore.Qt.QueuedConnection)
          QtCore.QThread.msleep(10)
          for row, form in enumerate(res):
          for column, item in enumerate(form):
          QtCore.QMetaObject.invokeMethod(self, "add_item",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(int, row), QtCore.Q_ARG(int, column), QtCore.Q_ARG(str, str(item)))
          QtCore.QThread.msleep(10)
          QtCore.QMetaObject.invokeMethod(self, "sort_items", QtCore.Qt.QueuedConnection)
          cursor.close()
          except:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'Error'), QtCore.Q_ARG(str, "Something went wrongnn"
          "Contact karol.chojnowski@digitalcaregroup.com"))





          share|improve this answer























          • Hmm, seems like it doesnt work completly. Threading works, but when i call sql_query method it works, then it closes program with pycharm info Process finished with exit code -1073740791 (0xC0000409) It seems that the problem is with writing to the table? During my main thread, clicking anything, it stops working sql_query?
            – Karol357
            Nov 20 at 20:02










          • I found and corrected it:self.tablewidget.insertRow(self.tablewidget.rowCount()) But got only first column, the rest is empty. Errors: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
            – Karol357
            Nov 20 at 20:21












          • looks good, thanks =)
            – Karol357
            Nov 20 at 20:59










          • Oh, i was too fast: QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) Exception in thread Thread-1: Traceback (most recent call last): File "C:UserskchojnowskiDocumentsPython_projectsGUI NataliaQApp.py", line 187, in sql_query QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found")) RuntimeError: QMetaObject.invokeMethod() call failed
            – Karol357
            Nov 20 at 21:14










          • @Karol357 Have you used my last code ?, I already correct those errors.
            – eyllanesc
            Nov 20 at 21:19











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390829%2fgui-not-responding-during-process%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          The use of processEvents() implies in most cases a bad design. If you have a heavy task, do not execute it in the main thread, execute it in another thread and send the necessary data to the main thread by means of signals or with QMetaObject::invokeMethod() (this last option will be used since it is not necessary so much connection).



          On the other hand you should only add the stylesheet once, if there are new widgets they will take as a basis the stylesheet.



          # -- coding: utf-8 --
          import threading
          from PyQt5 import QtGui, QtWidgets, QtCore
          import qdarkstyle
          import pyodbc

          class MainWindow(QtWidgets.QMainWindow):
          def __init__(self, parent=None):
          super(MainWindow,self).__init__(parent)

          self.main_frame()
          self.center() #center frame
          self.layout_init() #widgets layout

          def main_frame(self):
          ### actions on meenubar
          exitAct = QtWidgets.QAction('&Exit', self, shortcut='Ctrl+Q', statusTip='application')
          exitAct.triggered.connect(self.close)

          moreinfo = QtWidgets.QAction('&Help',self, statusTip='More information')
          moreinfo.triggered.connect(self.information)

          ### menubar
          menubar = self.menuBar()
          fileMenu = menubar.addMenu('&File')
          fileMenu.addAction(exitAct)
          fileMenu = menubar.addMenu('&Help')
          fileMenu.addAction(moreinfo)

          ### basic geometry and color
          self.setWindowTitle('Villain')
          self.setWindowIcon(QtGui.QIcon('dc1.png'))
          self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))

          def layout_init(self):
          central_widget = QtWidgets.QWidget()
          self.setCentralWidget(central_widget)

          ### widgets
          self.tablewidget = QtWidgets.QTableWidget()
          self.tablewidget.setColumnCount(4)
          self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
          self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
          self.tablewidget.horizontalHeader().setStretchLastSection(True)
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
          self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
          #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

          self.textbox = QtWidgets.QLineEdit()
          self.textbox.setPlaceholderText('IMEI')
          self.textbox.setEnabled(True)
          regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
          self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

          self.pb = QtWidgets.QPushButton(self.tr("Run process"))
          self.pb.setDisabled(True)
          self.textbox.textChanged.connect(self.disableButton)
          self.pb.clicked.connect(self.on_clicked_pb)

          self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
          self.clearbutton.setDisabled(True)
          self.clearbutton.clicked.connect(self.on_clicked_clear)

          ### make vidgets alive
          grid = QtWidgets.QGridLayout(central_widget)
          grid.addWidget(self.textbox)
          grid.addWidget(self.tablewidget)
          grid.addWidget(self.pb)
          grid.addWidget(self.clearbutton)

          self.table_performance()

          ### center main window
          def center(self):
          qr = self.frameGeometry()
          cp = QtWidgets.QDesktopWidget().availableGeometry().center()
          qr.moveCenter(cp)
          self.move(qr.topLeft())

          def information(self):
          QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
          'This is the prototype of the applicationnn'
          'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
          'Digital Care - Data Processing Team')


          @QtCore.pyqtSlot()
          def disableButton(self):
          val = bool(self.textbox.text())
          self.pb.setDisabled(not val)
          self.clearbutton.setDisabled(not val)

          ### run process button
          @QtCore.pyqtSlot()
          def on_clicked_pb(self):
          if self.textbox.text():
          threading.Thread(target=self.sql_query, daemon=True).start()
          ### clear all
          @QtCore.pyqtSlot()
          def on_clicked_clear(self):
          if self.textbox.text():
          self.textbox.clear()
          self.tablewidget.setRowCount(0)
          self.tablewidget.setColumnWidth(3, 200)

          def setCredentials(self, credentials):
          self._credentials = credentials

          def table_performance(self):
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setColumnWidth(3, 2500)
          self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)

          @QtCore.pyqtSlot(str, str)
          def show_warning(self, title, msg):
          QtWidgets.QMessageBox.information(self, title, msg)

          @QtCore.pyqtSlot()
          def clear_items(self):
          self.tablewidget.setRowCount(0)

          @QtCore.pyqtSlot(int, int, str)
          def add_item(self, row, column, val):
          if row >= self.tablewidget.rowCount():
          self.tablewidget.insertRow(self.tablewidget.rowCount())
          newitem = QtWidgets.QTableWidgetItem(val)
          self.tablewidget.setItem(row, column, newitem)

          @QtCore.pyqtSlot()
          def sort_items(self):
          self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)

          def sql_query(self):
          ser = "10.96.6.14"
          base = "PROD_WAREX2"
          username, pwd = self._credentials
          try:
          connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
          user=username, password=pwd)
          cursor = connection.cursor()
          res = cursor.execute(""" SELECT FI.FileNameTransformed,
          FI.OrderItemCode,
          FIR.Imported,
          FR.Row
          FROM [FileRows] AS FR
          JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
          JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
          WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
          if not cursor.rowcount:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found"))
          else:
          QtCore.QMetaObject.invokeMethod(self, "clear_items", QtCore.Qt.QueuedConnection)
          QtCore.QThread.msleep(10)
          for row, form in enumerate(res):
          for column, item in enumerate(form):
          QtCore.QMetaObject.invokeMethod(self, "add_item",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(int, row), QtCore.Q_ARG(int, column), QtCore.Q_ARG(str, str(item)))
          QtCore.QThread.msleep(10)
          QtCore.QMetaObject.invokeMethod(self, "sort_items", QtCore.Qt.QueuedConnection)
          cursor.close()
          except:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'Error'), QtCore.Q_ARG(str, "Something went wrongnn"
          "Contact karol.chojnowski@digitalcaregroup.com"))





          share|improve this answer























          • Hmm, seems like it doesnt work completly. Threading works, but when i call sql_query method it works, then it closes program with pycharm info Process finished with exit code -1073740791 (0xC0000409) It seems that the problem is with writing to the table? During my main thread, clicking anything, it stops working sql_query?
            – Karol357
            Nov 20 at 20:02










          • I found and corrected it:self.tablewidget.insertRow(self.tablewidget.rowCount()) But got only first column, the rest is empty. Errors: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
            – Karol357
            Nov 20 at 20:21












          • looks good, thanks =)
            – Karol357
            Nov 20 at 20:59










          • Oh, i was too fast: QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) Exception in thread Thread-1: Traceback (most recent call last): File "C:UserskchojnowskiDocumentsPython_projectsGUI NataliaQApp.py", line 187, in sql_query QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found")) RuntimeError: QMetaObject.invokeMethod() call failed
            – Karol357
            Nov 20 at 21:14










          • @Karol357 Have you used my last code ?, I already correct those errors.
            – eyllanesc
            Nov 20 at 21:19















          up vote
          1
          down vote



          accepted










          The use of processEvents() implies in most cases a bad design. If you have a heavy task, do not execute it in the main thread, execute it in another thread and send the necessary data to the main thread by means of signals or with QMetaObject::invokeMethod() (this last option will be used since it is not necessary so much connection).



          On the other hand you should only add the stylesheet once, if there are new widgets they will take as a basis the stylesheet.



          # -- coding: utf-8 --
          import threading
          from PyQt5 import QtGui, QtWidgets, QtCore
          import qdarkstyle
          import pyodbc

          class MainWindow(QtWidgets.QMainWindow):
          def __init__(self, parent=None):
          super(MainWindow,self).__init__(parent)

          self.main_frame()
          self.center() #center frame
          self.layout_init() #widgets layout

          def main_frame(self):
          ### actions on meenubar
          exitAct = QtWidgets.QAction('&Exit', self, shortcut='Ctrl+Q', statusTip='application')
          exitAct.triggered.connect(self.close)

          moreinfo = QtWidgets.QAction('&Help',self, statusTip='More information')
          moreinfo.triggered.connect(self.information)

          ### menubar
          menubar = self.menuBar()
          fileMenu = menubar.addMenu('&File')
          fileMenu.addAction(exitAct)
          fileMenu = menubar.addMenu('&Help')
          fileMenu.addAction(moreinfo)

          ### basic geometry and color
          self.setWindowTitle('Villain')
          self.setWindowIcon(QtGui.QIcon('dc1.png'))
          self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))

          def layout_init(self):
          central_widget = QtWidgets.QWidget()
          self.setCentralWidget(central_widget)

          ### widgets
          self.tablewidget = QtWidgets.QTableWidget()
          self.tablewidget.setColumnCount(4)
          self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
          self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
          self.tablewidget.horizontalHeader().setStretchLastSection(True)
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
          self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
          #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

          self.textbox = QtWidgets.QLineEdit()
          self.textbox.setPlaceholderText('IMEI')
          self.textbox.setEnabled(True)
          regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
          self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

          self.pb = QtWidgets.QPushButton(self.tr("Run process"))
          self.pb.setDisabled(True)
          self.textbox.textChanged.connect(self.disableButton)
          self.pb.clicked.connect(self.on_clicked_pb)

          self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
          self.clearbutton.setDisabled(True)
          self.clearbutton.clicked.connect(self.on_clicked_clear)

          ### make vidgets alive
          grid = QtWidgets.QGridLayout(central_widget)
          grid.addWidget(self.textbox)
          grid.addWidget(self.tablewidget)
          grid.addWidget(self.pb)
          grid.addWidget(self.clearbutton)

          self.table_performance()

          ### center main window
          def center(self):
          qr = self.frameGeometry()
          cp = QtWidgets.QDesktopWidget().availableGeometry().center()
          qr.moveCenter(cp)
          self.move(qr.topLeft())

          def information(self):
          QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
          'This is the prototype of the applicationnn'
          'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
          'Digital Care - Data Processing Team')


          @QtCore.pyqtSlot()
          def disableButton(self):
          val = bool(self.textbox.text())
          self.pb.setDisabled(not val)
          self.clearbutton.setDisabled(not val)

          ### run process button
          @QtCore.pyqtSlot()
          def on_clicked_pb(self):
          if self.textbox.text():
          threading.Thread(target=self.sql_query, daemon=True).start()
          ### clear all
          @QtCore.pyqtSlot()
          def on_clicked_clear(self):
          if self.textbox.text():
          self.textbox.clear()
          self.tablewidget.setRowCount(0)
          self.tablewidget.setColumnWidth(3, 200)

          def setCredentials(self, credentials):
          self._credentials = credentials

          def table_performance(self):
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setColumnWidth(3, 2500)
          self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)

          @QtCore.pyqtSlot(str, str)
          def show_warning(self, title, msg):
          QtWidgets.QMessageBox.information(self, title, msg)

          @QtCore.pyqtSlot()
          def clear_items(self):
          self.tablewidget.setRowCount(0)

          @QtCore.pyqtSlot(int, int, str)
          def add_item(self, row, column, val):
          if row >= self.tablewidget.rowCount():
          self.tablewidget.insertRow(self.tablewidget.rowCount())
          newitem = QtWidgets.QTableWidgetItem(val)
          self.tablewidget.setItem(row, column, newitem)

          @QtCore.pyqtSlot()
          def sort_items(self):
          self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)

          def sql_query(self):
          ser = "10.96.6.14"
          base = "PROD_WAREX2"
          username, pwd = self._credentials
          try:
          connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
          user=username, password=pwd)
          cursor = connection.cursor()
          res = cursor.execute(""" SELECT FI.FileNameTransformed,
          FI.OrderItemCode,
          FIR.Imported,
          FR.Row
          FROM [FileRows] AS FR
          JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
          JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
          WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
          if not cursor.rowcount:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found"))
          else:
          QtCore.QMetaObject.invokeMethod(self, "clear_items", QtCore.Qt.QueuedConnection)
          QtCore.QThread.msleep(10)
          for row, form in enumerate(res):
          for column, item in enumerate(form):
          QtCore.QMetaObject.invokeMethod(self, "add_item",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(int, row), QtCore.Q_ARG(int, column), QtCore.Q_ARG(str, str(item)))
          QtCore.QThread.msleep(10)
          QtCore.QMetaObject.invokeMethod(self, "sort_items", QtCore.Qt.QueuedConnection)
          cursor.close()
          except:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'Error'), QtCore.Q_ARG(str, "Something went wrongnn"
          "Contact karol.chojnowski@digitalcaregroup.com"))





          share|improve this answer























          • Hmm, seems like it doesnt work completly. Threading works, but when i call sql_query method it works, then it closes program with pycharm info Process finished with exit code -1073740791 (0xC0000409) It seems that the problem is with writing to the table? During my main thread, clicking anything, it stops working sql_query?
            – Karol357
            Nov 20 at 20:02










          • I found and corrected it:self.tablewidget.insertRow(self.tablewidget.rowCount()) But got only first column, the rest is empty. Errors: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
            – Karol357
            Nov 20 at 20:21












          • looks good, thanks =)
            – Karol357
            Nov 20 at 20:59










          • Oh, i was too fast: QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) Exception in thread Thread-1: Traceback (most recent call last): File "C:UserskchojnowskiDocumentsPython_projectsGUI NataliaQApp.py", line 187, in sql_query QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found")) RuntimeError: QMetaObject.invokeMethod() call failed
            – Karol357
            Nov 20 at 21:14










          • @Karol357 Have you used my last code ?, I already correct those errors.
            – eyllanesc
            Nov 20 at 21:19













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          The use of processEvents() implies in most cases a bad design. If you have a heavy task, do not execute it in the main thread, execute it in another thread and send the necessary data to the main thread by means of signals or with QMetaObject::invokeMethod() (this last option will be used since it is not necessary so much connection).



          On the other hand you should only add the stylesheet once, if there are new widgets they will take as a basis the stylesheet.



          # -- coding: utf-8 --
          import threading
          from PyQt5 import QtGui, QtWidgets, QtCore
          import qdarkstyle
          import pyodbc

          class MainWindow(QtWidgets.QMainWindow):
          def __init__(self, parent=None):
          super(MainWindow,self).__init__(parent)

          self.main_frame()
          self.center() #center frame
          self.layout_init() #widgets layout

          def main_frame(self):
          ### actions on meenubar
          exitAct = QtWidgets.QAction('&Exit', self, shortcut='Ctrl+Q', statusTip='application')
          exitAct.triggered.connect(self.close)

          moreinfo = QtWidgets.QAction('&Help',self, statusTip='More information')
          moreinfo.triggered.connect(self.information)

          ### menubar
          menubar = self.menuBar()
          fileMenu = menubar.addMenu('&File')
          fileMenu.addAction(exitAct)
          fileMenu = menubar.addMenu('&Help')
          fileMenu.addAction(moreinfo)

          ### basic geometry and color
          self.setWindowTitle('Villain')
          self.setWindowIcon(QtGui.QIcon('dc1.png'))
          self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))

          def layout_init(self):
          central_widget = QtWidgets.QWidget()
          self.setCentralWidget(central_widget)

          ### widgets
          self.tablewidget = QtWidgets.QTableWidget()
          self.tablewidget.setColumnCount(4)
          self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
          self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
          self.tablewidget.horizontalHeader().setStretchLastSection(True)
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
          self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
          #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

          self.textbox = QtWidgets.QLineEdit()
          self.textbox.setPlaceholderText('IMEI')
          self.textbox.setEnabled(True)
          regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
          self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

          self.pb = QtWidgets.QPushButton(self.tr("Run process"))
          self.pb.setDisabled(True)
          self.textbox.textChanged.connect(self.disableButton)
          self.pb.clicked.connect(self.on_clicked_pb)

          self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
          self.clearbutton.setDisabled(True)
          self.clearbutton.clicked.connect(self.on_clicked_clear)

          ### make vidgets alive
          grid = QtWidgets.QGridLayout(central_widget)
          grid.addWidget(self.textbox)
          grid.addWidget(self.tablewidget)
          grid.addWidget(self.pb)
          grid.addWidget(self.clearbutton)

          self.table_performance()

          ### center main window
          def center(self):
          qr = self.frameGeometry()
          cp = QtWidgets.QDesktopWidget().availableGeometry().center()
          qr.moveCenter(cp)
          self.move(qr.topLeft())

          def information(self):
          QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
          'This is the prototype of the applicationnn'
          'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
          'Digital Care - Data Processing Team')


          @QtCore.pyqtSlot()
          def disableButton(self):
          val = bool(self.textbox.text())
          self.pb.setDisabled(not val)
          self.clearbutton.setDisabled(not val)

          ### run process button
          @QtCore.pyqtSlot()
          def on_clicked_pb(self):
          if self.textbox.text():
          threading.Thread(target=self.sql_query, daemon=True).start()
          ### clear all
          @QtCore.pyqtSlot()
          def on_clicked_clear(self):
          if self.textbox.text():
          self.textbox.clear()
          self.tablewidget.setRowCount(0)
          self.tablewidget.setColumnWidth(3, 200)

          def setCredentials(self, credentials):
          self._credentials = credentials

          def table_performance(self):
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setColumnWidth(3, 2500)
          self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)

          @QtCore.pyqtSlot(str, str)
          def show_warning(self, title, msg):
          QtWidgets.QMessageBox.information(self, title, msg)

          @QtCore.pyqtSlot()
          def clear_items(self):
          self.tablewidget.setRowCount(0)

          @QtCore.pyqtSlot(int, int, str)
          def add_item(self, row, column, val):
          if row >= self.tablewidget.rowCount():
          self.tablewidget.insertRow(self.tablewidget.rowCount())
          newitem = QtWidgets.QTableWidgetItem(val)
          self.tablewidget.setItem(row, column, newitem)

          @QtCore.pyqtSlot()
          def sort_items(self):
          self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)

          def sql_query(self):
          ser = "10.96.6.14"
          base = "PROD_WAREX2"
          username, pwd = self._credentials
          try:
          connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
          user=username, password=pwd)
          cursor = connection.cursor()
          res = cursor.execute(""" SELECT FI.FileNameTransformed,
          FI.OrderItemCode,
          FIR.Imported,
          FR.Row
          FROM [FileRows] AS FR
          JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
          JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
          WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
          if not cursor.rowcount:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found"))
          else:
          QtCore.QMetaObject.invokeMethod(self, "clear_items", QtCore.Qt.QueuedConnection)
          QtCore.QThread.msleep(10)
          for row, form in enumerate(res):
          for column, item in enumerate(form):
          QtCore.QMetaObject.invokeMethod(self, "add_item",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(int, row), QtCore.Q_ARG(int, column), QtCore.Q_ARG(str, str(item)))
          QtCore.QThread.msleep(10)
          QtCore.QMetaObject.invokeMethod(self, "sort_items", QtCore.Qt.QueuedConnection)
          cursor.close()
          except:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'Error'), QtCore.Q_ARG(str, "Something went wrongnn"
          "Contact karol.chojnowski@digitalcaregroup.com"))





          share|improve this answer














          The use of processEvents() implies in most cases a bad design. If you have a heavy task, do not execute it in the main thread, execute it in another thread and send the necessary data to the main thread by means of signals or with QMetaObject::invokeMethod() (this last option will be used since it is not necessary so much connection).



          On the other hand you should only add the stylesheet once, if there are new widgets they will take as a basis the stylesheet.



          # -- coding: utf-8 --
          import threading
          from PyQt5 import QtGui, QtWidgets, QtCore
          import qdarkstyle
          import pyodbc

          class MainWindow(QtWidgets.QMainWindow):
          def __init__(self, parent=None):
          super(MainWindow,self).__init__(parent)

          self.main_frame()
          self.center() #center frame
          self.layout_init() #widgets layout

          def main_frame(self):
          ### actions on meenubar
          exitAct = QtWidgets.QAction('&Exit', self, shortcut='Ctrl+Q', statusTip='application')
          exitAct.triggered.connect(self.close)

          moreinfo = QtWidgets.QAction('&Help',self, statusTip='More information')
          moreinfo.triggered.connect(self.information)

          ### menubar
          menubar = self.menuBar()
          fileMenu = menubar.addMenu('&File')
          fileMenu.addAction(exitAct)
          fileMenu = menubar.addMenu('&Help')
          fileMenu.addAction(moreinfo)

          ### basic geometry and color
          self.setWindowTitle('Villain')
          self.setWindowIcon(QtGui.QIcon('dc1.png'))
          self.setStyleSheet((qdarkstyle.load_stylesheet_pyqt5()))

          def layout_init(self):
          central_widget = QtWidgets.QWidget()
          self.setCentralWidget(central_widget)

          ### widgets
          self.tablewidget = QtWidgets.QTableWidget()
          self.tablewidget.setColumnCount(4)
          self.tablewidget.setHorizontalHeaderLabels(["FileNameTransformed", "OrderItemCode", "Imported", "Row"])
          self.tablewidget.horizontalHeader().setDefaultAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
          self.tablewidget.horizontalHeader().setStretchLastSection(True)
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
          self.tablewidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
          #self.tablewidget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)

          self.textbox = QtWidgets.QLineEdit()
          self.textbox.setPlaceholderText('IMEI')
          self.textbox.setEnabled(True)
          regexp = QtCore.QRegExp('^(0d+|[1-9][0-9]+)$') #IMEI = only int
          self.textbox.setValidator(QtGui.QRegExpValidator(regexp))

          self.pb = QtWidgets.QPushButton(self.tr("Run process"))
          self.pb.setDisabled(True)
          self.textbox.textChanged.connect(self.disableButton)
          self.pb.clicked.connect(self.on_clicked_pb)

          self.clearbutton = QtWidgets.QPushButton(self.tr("Clear all"))
          self.clearbutton.setDisabled(True)
          self.clearbutton.clicked.connect(self.on_clicked_clear)

          ### make vidgets alive
          grid = QtWidgets.QGridLayout(central_widget)
          grid.addWidget(self.textbox)
          grid.addWidget(self.tablewidget)
          grid.addWidget(self.pb)
          grid.addWidget(self.clearbutton)

          self.table_performance()

          ### center main window
          def center(self):
          qr = self.frameGeometry()
          cp = QtWidgets.QDesktopWidget().availableGeometry().center()
          qr.moveCenter(cp)
          self.move(qr.topLeft())

          def information(self):
          QtWidgets.QMessageBox.information(self,'Information','Version: 1.19.11.18n'
          'This is the prototype of the applicationnn'
          'Please, contact karol.chojnowski@digitalcaregroup.com for comments and suggestionsnn'
          'Digital Care - Data Processing Team')


          @QtCore.pyqtSlot()
          def disableButton(self):
          val = bool(self.textbox.text())
          self.pb.setDisabled(not val)
          self.clearbutton.setDisabled(not val)

          ### run process button
          @QtCore.pyqtSlot()
          def on_clicked_pb(self):
          if self.textbox.text():
          threading.Thread(target=self.sql_query, daemon=True).start()
          ### clear all
          @QtCore.pyqtSlot()
          def on_clicked_clear(self):
          if self.textbox.text():
          self.textbox.clear()
          self.tablewidget.setRowCount(0)
          self.tablewidget.setColumnWidth(3, 200)

          def setCredentials(self, credentials):
          self._credentials = credentials

          def table_performance(self):
          self.tablewidget.resizeColumnsToContents()
          self.tablewidget.setColumnWidth(3, 2500)
          self.tablewidget.setHorizontalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)

          @QtCore.pyqtSlot(str, str)
          def show_warning(self, title, msg):
          QtWidgets.QMessageBox.information(self, title, msg)

          @QtCore.pyqtSlot()
          def clear_items(self):
          self.tablewidget.setRowCount(0)

          @QtCore.pyqtSlot(int, int, str)
          def add_item(self, row, column, val):
          if row >= self.tablewidget.rowCount():
          self.tablewidget.insertRow(self.tablewidget.rowCount())
          newitem = QtWidgets.QTableWidgetItem(val)
          self.tablewidget.setItem(row, column, newitem)

          @QtCore.pyqtSlot()
          def sort_items(self):
          self.tablewidget.sortItems(0, order=QtCore.Qt.DescendingOrder)

          def sql_query(self):
          ser = "10.96.6.14"
          base = "PROD_WAREX2"
          username, pwd = self._credentials
          try:
          connection = pyodbc.connect(driver='{SQL Server}', server=ser, database=base,
          user=username, password=pwd)
          cursor = connection.cursor()
          res = cursor.execute(""" SELECT FI.FileNameTransformed,
          FI.OrderItemCode,
          FIR.Imported,
          FR.Row
          FROM [FileRows] AS FR
          JOIN [FileImportRows] AS FIR ON FR.RowId = FIR.RowId
          JOIN [FileImports] AS FI ON FIR.FileImportId = FI.Id
          WHERE FR.Row LIKE ? """, ('%' + self.textbox.text() + '%'))
          if not cursor.rowcount:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found"))
          else:
          QtCore.QMetaObject.invokeMethod(self, "clear_items", QtCore.Qt.QueuedConnection)
          QtCore.QThread.msleep(10)
          for row, form in enumerate(res):
          for column, item in enumerate(form):
          QtCore.QMetaObject.invokeMethod(self, "add_item",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(int, row), QtCore.Q_ARG(int, column), QtCore.Q_ARG(str, str(item)))
          QtCore.QThread.msleep(10)
          QtCore.QMetaObject.invokeMethod(self, "sort_items", QtCore.Qt.QueuedConnection)
          cursor.close()
          except:
          QtCore.QMetaObject.invokeMethod(self, "show_warning",
          QtCore.Qt.QueuedConnection,
          QtCore.Q_ARG(str, 'Error'), QtCore.Q_ARG(str, "Something went wrongnn"
          "Contact karol.chojnowski@digitalcaregroup.com"))






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 at 20:46

























          answered Nov 20 at 15:39









          eyllanesc

          71.3k93053




          71.3k93053












          • Hmm, seems like it doesnt work completly. Threading works, but when i call sql_query method it works, then it closes program with pycharm info Process finished with exit code -1073740791 (0xC0000409) It seems that the problem is with writing to the table? During my main thread, clicking anything, it stops working sql_query?
            – Karol357
            Nov 20 at 20:02










          • I found and corrected it:self.tablewidget.insertRow(self.tablewidget.rowCount()) But got only first column, the rest is empty. Errors: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
            – Karol357
            Nov 20 at 20:21












          • looks good, thanks =)
            – Karol357
            Nov 20 at 20:59










          • Oh, i was too fast: QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) Exception in thread Thread-1: Traceback (most recent call last): File "C:UserskchojnowskiDocumentsPython_projectsGUI NataliaQApp.py", line 187, in sql_query QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found")) RuntimeError: QMetaObject.invokeMethod() call failed
            – Karol357
            Nov 20 at 21:14










          • @Karol357 Have you used my last code ?, I already correct those errors.
            – eyllanesc
            Nov 20 at 21:19


















          • Hmm, seems like it doesnt work completly. Threading works, but when i call sql_query method it works, then it closes program with pycharm info Process finished with exit code -1073740791 (0xC0000409) It seems that the problem is with writing to the table? During my main thread, clicking anything, it stops working sql_query?
            – Karol357
            Nov 20 at 20:02










          • I found and corrected it:self.tablewidget.insertRow(self.tablewidget.rowCount()) But got only first column, the rest is empty. Errors: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
            – Karol357
            Nov 20 at 20:21












          • looks good, thanks =)
            – Karol357
            Nov 20 at 20:59










          • Oh, i was too fast: QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) Exception in thread Thread-1: Traceback (most recent call last): File "C:UserskchojnowskiDocumentsPython_projectsGUI NataliaQApp.py", line 187, in sql_query QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found")) RuntimeError: QMetaObject.invokeMethod() call failed
            – Karol357
            Nov 20 at 21:14










          • @Karol357 Have you used my last code ?, I already correct those errors.
            – eyllanesc
            Nov 20 at 21:19
















          Hmm, seems like it doesnt work completly. Threading works, but when i call sql_query method it works, then it closes program with pycharm info Process finished with exit code -1073740791 (0xC0000409) It seems that the problem is with writing to the table? During my main thread, clicking anything, it stops working sql_query?
          – Karol357
          Nov 20 at 20:02




          Hmm, seems like it doesnt work completly. Threading works, but when i call sql_query method it works, then it closes program with pycharm info Process finished with exit code -1073740791 (0xC0000409) It seems that the problem is with writing to the table? During my main thread, clicking anything, it stops working sql_query?
          – Karol357
          Nov 20 at 20:02












          I found and corrected it:self.tablewidget.insertRow(self.tablewidget.rowCount()) But got only first column, the rest is empty. Errors: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
          – Karol357
          Nov 20 at 20:21






          I found and corrected it:self.tablewidget.insertRow(self.tablewidget.rowCount()) But got only first column, the rest is empty. Errors: QBasicTimer::start: QBasicTimer can only be used with threads started with QThread QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
          – Karol357
          Nov 20 at 20:21














          looks good, thanks =)
          – Karol357
          Nov 20 at 20:59




          looks good, thanks =)
          – Karol357
          Nov 20 at 20:59












          Oh, i was too fast: QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) Exception in thread Thread-1: Traceback (most recent call last): File "C:UserskchojnowskiDocumentsPython_projectsGUI NataliaQApp.py", line 187, in sql_query QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found")) RuntimeError: QMetaObject.invokeMethod() call failed
          – Karol357
          Nov 20 at 21:14




          Oh, i was too fast: QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) QMetaObject::invokeMethod: No such method MainWindow::show_warning(QString,QString) Candidates are: show_warning(int) Exception in thread Thread-1: Traceback (most recent call last): File "C:UserskchojnowskiDocumentsPython_projectsGUI NataliaQApp.py", line 187, in sql_query QtCore.Q_ARG(str, 'IMEI'), QtCore.Q_ARG(str, "No items found")) RuntimeError: QMetaObject.invokeMethod() call failed
          – Karol357
          Nov 20 at 21:14












          @Karol357 Have you used my last code ?, I already correct those errors.
          – eyllanesc
          Nov 20 at 21:19




          @Karol357 Have you used my last code ?, I already correct those errors.
          – eyllanesc
          Nov 20 at 21:19


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390829%2fgui-not-responding-during-process%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'