0

I'm doing a login page, mysql query in a separate thread, I can't get it from login_ui lineEdit.text (), I decided to try through signals and slots

I can pass the string through signal.connect(same.funktion) trigger function. But it is not passed to the run() function.

Or tell me how to start the stream and pass the required string there.

Thank you.

class CheckLogin(QtCore.QThread):
    result_request_password = QtCore.pyqtSignal(str, str, str)
    result_anim = QtCore.pyqtSignal(bool)
    login_input = QtCore.pyqtSignal(str)
    
    def __init__(self, parent=None):
        super().__init__(parent)
        # self.login_input.connect(self.text)
        
    # def text (self, input):
    #     login_in = input
    #     return  login_in
    
    def run(self):
        print(self.login_input.signal())
  • `run()` is not called explicitly, but only internally by the thread. Do you need the string while the thread is already running? And why do you need to have the sql part in a separate thread? – musicamante Feb 09 '23 at 10:39
  • so that when the thread starts, the login and password (string) are transferred there. In a separate thread because there will be many such tasks in the future, and I want to figure it out right away. – BigBlackOwl Feb 09 '23 at 11:49
  • Then just add those data in the constructor of the worker object by altering its `__init__` arguments. Note that premature optimization is rarely a good choice (and if you're a beginner, it's usually the *wrong* one); use threading *if* you really need it, not because you think that maybe you will. – musicamante Feb 09 '23 at 11:57
  • I did not quite understand how exactly to change __init__ @musicamante – BigBlackOwl Feb 09 '23 at 12:12
  • Change to `def __init__(self, text, parent=None):` and create it with `myThread = CheckLogin(self.lineEdit.text())`. Note that signals have no `signal` attribute, and `login_input` has a required argument which should be used with `emit()` instead. I strongly suggest you to take your time, as it seems that you're trying to skip some steps in your learning: Qt may seem easy at first, but it's a complex toolkit that requires some amount of experience and knowledge of OOP, which you seem to lack, based on your comment and code. Try to learn more about classes, instances, methods and attributes. – musicamante Feb 09 '23 at 12:35
  • i work with MySQL, you think what need to do all requests in main thread, for example: get 10000 line of data and more? And what to do with freezing GUI. – BigBlackOwl Feb 09 '23 at 12:42
  • 'self.check_login_thread.start() input_login = self.login_ui.login_line.text() self.check_login_thread.login_input.emit(input_login) ' – BigBlackOwl Feb 09 '23 at 12:49
  • That depends on how you're using the data. If you need to display it (for instance, in a QTableView) threading won't help you, and if you want to use a QTableWidget that would even be worse; Qt also has the QtSql module that is usually fast and reliable (and since it works on the C++ side of Qt, it's also faster). If you need to *process* that data (doing searches or computation) then threading is probably *not* the choice, since threads in python are *not* concurrent and if you're not careful enough, you may end up having poor performance while keeping the GUI frozen anyway. – musicamante Feb 09 '23 at 12:50
  • Thanks, i think about this. it's second version of this program, and i want to try this way and test it. – BigBlackOwl Feb 09 '23 at 12:54

0 Answers0