#๐ PyQt5 Error #pyqt5
113 messages ยท Page 1 of 1 (latest)
@sudden scarab
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle(' ')
self.setGeometry(100, 100, 1050, 700)
self.browser = QWebEngineView()
self.browser.setHtml(html_content)
self.setCentralWidget(self.browser)
self.channel = QWebChannel()
self.browser.page().setWebChannel(self.channel)
self.channel.registerObject("bridge", self)
class AuthWindow(QMainWindow):
def __init__(self):
super().__init__()
self.data = None
self.password = None
self.license_key = None
self.username = None
self.setWindowTitle(' ')
self.setGeometry(100, 100, 1050, 700)
self.browser = QWebEngineView()
self.browser.setHtml(auth_content)
self.setCentralWidget(self.browser)
self.channel = QWebChannel()
self.browser.page().setWebChannel(self.channel)
self.channel.registerObject("bridge", self)
def login(self):
print(self.username, self.password)
try:
keyauthapp.login(self.username, self.password)
print("logged in")
response = jsonify({"message": "success"})
response.status_code = 200
w = MainWindow()
w.show()
self.close()
except Exception as e:
print(f"{e}")
return jsonify({"error": str(e)}), 400
def register(self):
print(self.username, self.password, self.license_key)
try:
keyauthapp.register(self.username, self.password, self.license_key)
response = jsonify({"message": "success"})
response.status_code = 200
w = MainWindow()
w.show()
self.close()
except Exception as e:
print(f"{e}")
return jsonify({"error": str(e)}), 400
@app.route('/auth', methods=['POST'])
@cross_origin()
def auth():
data = request.json
username = data.get('username')
password = data.get('password')
license_key = data.get('license_key')
if not username or not password:
return jsonify({"error": "error"}), 400
window = AuthWindow()
window.username = username
window.password = password
window.license_key = license_key
if license_key:
return window.register()
else:
return window.login()
if __name__ == '__main__':
system("cls")
CORS(app)
flask_thread = Thread(target=lambda: app.run(port=5000, debug=False, use_reloader=False)).start()
app = QApplication(sys.argv)
window = AuthWindow()
window.setFixedSize(800, 650)
window.setWindowFlags(Qt.Window | Qt.WindowStaysOnTopHint)
window.setAttribute(Qt.WA_TranslucentBackground)
hook_thread = threading.Thread(target=keyboard_hook, daemon=True).start()
set_dark_mode(int(window.winId()))
window.show()
exit(app.exec_())
QObject::startTimer: Timers can only be used with threads started with QThread
Something in your code is starting a QTimer. As QTimers depend on Qt's event loop, you'd preferably want to stay within Qt's ecosystem. So you'd want to use QThread rather than stdlib threads. Here are some decent resources if you want some general guidance on how to use them:
Sure, you're importing it. But the error complains about it being started. Are you starting a QTimer somewhere or do you have an idea of what could be?
it's gray, i mean QTimer is not being used anywhere in my code
Yeah, at least not in the code you've shared. Since I doubt Flask is starting a QTimer, can you share what the target function here is doing?
hook_thread = threading.Thread(target=keyboard_hook, daemon=True).start()
def keyboard_hook():
global script_active
while True:
if GetAsyncKeyState(ready_toggle_key):
toggle_script()
time.sleep(0.3)
Alright, GetAsyncKeyState seems to be a WinAPI function so probably not that. Maybe toggle_script and whatever that's calling?
!paste if you can share the entire code, that would work as well
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
i can't, sorry
def toggle_script():
global script_active
script_active = not script_active
if script_active:
start_recoil_control()
return "enabled" if script_active else "disabled"
in start_recoil_control all the same:
if is_authenticated:
while script_active:
if GetAsyncKeyState(0x01) & 0x8000:
and it's can be called after authentication, problem in authentication so basically it's not starting and error is not here
hook_thread = threading.Thread(target=keyboard_hook, daemon=True).start()
removed and this error still appears
Are you able to at least share the part of the code starting the timer? I don't see anything in what you've shared that could possibly start one.
i have no any timers in my code gray means it's not used anywhere in my full code
error exactly here:
w = MainWindow()
w.show()
but idk how to fix it
Ah, I see what's happening.
You can't start a window like that since it's not within Qt's own event loop.
Since your route is effectively invoked by Flask using its own threads, Qt can't really start a window there since that needs to be done within the event loop.
There's probably workarounds for fixing this but I'll suggest just splitting the Flask code and the Qt code into separate modules then have your auth window send the requests to Flask and have Flask start a new process with your actual application.
-# There's also Qt Http Server as an alternative to Flask but, long-term, you'd still want to do these things separately.
Yeah my suggestion in python-discussion was to have them be separate processes too
Is it possible to compile 2 .py apps into .exe ?
You can use the subprocessmodule to launch new processes
yeah but i need like to create second file(showing src) and starting it
So what exactly is the relationship between your gui and the flask server?
i'm still not quite understanding what you're doing
@app.route('/update_settings', methods=['POST'])
def update_settings_route():
global script_active, toggle_key, crouch_key, selected_weapon, selected_scope, x_speed, y_speed, menu_key, ready_crouch_key, ready_toggle_key
data = request.json
print(data)
if data.get('id') == "toggle_key":
toggle_key = data.get('value')
if toggle_key == "F2":
toggle_key = 0x71
ready_toggle_key = toggle_key
if toggle_key == "F3":
toggle_key = 0x7
if toggle_key == "F5":
toggle_key = 0x74
ready_toggle_key = toggle_key
if toggle_key == "F6":
toggle_key = 0x75
ready_toggle_key = toggle_key
if toggle_key == "F7":
toggle_key = 0x76
ready_toggle_key = toggle_key
if toggle_key == "F8":
toggle_key = 0x77
ready_toggle_key = toggle_key
elif data.get('id') == "crouch_key":
crouch_key = data.get('value')
if crouch_key == "Ctrl":
crouch_key = 0x11
if crouch_key == "Shift":
crouch_key = 0x10
ready_crouch_key = crouch_key
elif crouch_key == "Alt":
crouch_key = 0x12
ready_crouch_key = crouch_key
elif crouch_key == "C":
crouch_key = 0x43
ready_crouch_key = crouch_key
elif data.get('id') == "selected_weapon":
selected_weapon = data.get('value')
elif data.get('id') == "selected_scope":
selected_scope = data.get('value')
update_scope(selected_scope)
# elif data.get('id') == "menu_key":
# menu_key = data.get('value')
# if menu_key == "Insert":
# menu_key = keyboard.Key.insert
# elif menu_key == "Home":
# menu_key = keyboard.Key.home
elif data.get('id') == "x_speed":
x_speed = data.get('value')
x_speed_int = int(x_speed)
update_x_speed(x_speed_int)
elif data.get('id') == "y_speed":
y_speed = data.get('value')
y_speed_int = int(y_speed)
update_y_speed(y_speed_int)
script for game, updating user settings
shit code but i think you see what i mean
Why do you need flask for this?
what can i use else?
Can you accomplish this with just a Qt gui?
that's accessable via a web browser? If that's so then you don't need Qt - just use chrome or whatever browser you want
I think they mean the stuff you're doing in Flask. You're already using Qt Web Engine anyways.
Yeah there's no reason to bring network communication protocols in to a completely localized gui
no, it's a script for game not a website or smth
That's what i'm saying. Then you don't need to use a webserver
Just implement your gui in Qt
sorry, my english is not so good. implement html and css in qt?
no. If you're not making a website, you don't need html and css to begin with
your gui can be done completely with Qt framework
yeah but it's already done on html&css
Ok. Then serve it up with flask and use chrome/safari/firefox/edge to view it. No qt needed then
this code is starting script in your pc, i can't do that
why not?
?
the same reason why your pc cant be turned off by clicking button on website?
or you mean starting flask locally
Ok just looking at the code you shared at the beginning here
So who is making the POST to your auth route?
in this way it will work without qt, but other dev wants gui exactly in qt
js
from where
from web
from this?
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle(' ')
self.setGeometry(100, 100, 1050, 700)
self.browser = QWebEngineView()
self.browser.setHtml(html_content)
self.setCentralWidget(self.browser)
self.channel = QWebChannel()
self.browser.page().setWebChannel(self.channel)
self.channel.registerObject("bridge", self)
Does that html_content have the js that sends a POST to your auth route?
ok, but auth_content has the HTML that POST's to your auth route?
ok
so you're trying to implement both a browser/client and a server in the same process
the flask server should actually serve that html content as another route
so you use a client process (like chrome for example) to go to http://localhost:5000/login or whatever you call it
that login route will serve the HTML
which contains the JS to POST to /auth
you don't need Qt to create a browser window
it's not my decision
It seems like you're not actually giving him what he wants then. You're giving him a browser in Qt
why not anyway it works
If this is what he wants, then you need to abandon Flask and HTML/CSS altogether
just do everything in qt
he wants better ui and that's all
i understand what you mean but i dont know qss so good
directly? what you mean
If Qt Widgets is not a requirement, consider QML or just using a standard web view.
You just have a window with a couple of text entries right?
huh? no
i'm not doing that because i used qtwebbrowser
even forget about qt creator
What exactly are your requirements for this project?
30,000ft view of what you're trying to accomplish
Sounds like some other guy is giving you requirements. Like "make a better gui"
what does that mean
macros for recoil control in game
Ok. And you're trying to create a Gui to configure it?
it's already working im trying to implement second window(authentication) now
okay, for example separated code
- flask
- qt
even if i receive username, login in flask code, how would i use it in qt code?
I still don't think you need both. In my opinion, you should use one or the other
Either serve everything in flask and use a browser to view it, or create the entire gui in Qt
๐คท not my problem. I'm just speaking from experience here
I've given you my suggestions. It's up to you do take it or leave it
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.