QtAxContainer.QAxWidget can't from RDP control my windows computer
-
When i used QtAxContainer.QAxWidget to control my machine, There is a
trouble,my QT application show a white picture 。
i show you some picture。!
i need your help,thank you very much!import sys from ui_untitled import * class RemoteDesktopWindow(QMainWindow): def __init__(self, server_ip, username, password): super().__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # # 创建AxMsRdpClient对象 # 设置服务器地址 self.ui.axWidget.setProperty('Server', server_ip) # 设置用户名 self.ui.axWidget.setProperty('UserName', username) # 设置密码 # 设置服务器地址 self.ui.axWidget.dynamicCall('put_AdvancedSettings2.ClearTextPassword(QString)', password) self.afpAdvancedObject = self.ui.axWidget.querySubObject("AdvancedSettings7") # self.afpAdvancedObject.setProperty("EnableCredSspSupport", True) # 连接远程桌面 self.ui.axWidget.dynamicCall('Connect()') # 设置其他属性... if __name__ == "__main__": app = QApplication(sys.argv) window = RemoteDesktopWindow("ip", "DESKTOP-0QR3E2C\\testserver", "1234.abcde") window.show() sys.exit(app.exec()) ``` # -*- coding: utf-8 -*- ################################################################################ ## Form generated from reading UI file 'untitled.ui' ## ## Created by: Qt User Interface Compiler version 6.5.2 ## ## WARNING! All changes made in this file will be lost when recompiling UI file! ################################################################################ from PySide6.QtAxContainer import QAxWidget from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, QMetaObject, QObject, QPoint, QRect, QSize, QTime, QUrl, Qt) from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QGradient, QIcon, QImage, QKeySequence, QLinearGradient, QPainter, QPalette, QPixmap, QRadialGradient, QTransform) from PySide6.QtWidgets import (QApplication, QGridLayout, QMainWindow, QMenuBar, QSizePolicy, QStatusBar, QWidget) class Ui_MainWindow(object): def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(800, 600) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") self.gridLayout = QGridLayout(self.centralwidget) self.gridLayout.setObjectName(u"gridLayout") self.axWidget = QAxWidget(self.centralwidget) self.axWidget.setControl(u"{1df7c823-b2d4-4b54-975a-f2ac5d7cf8b8}") self.axWidget.setObjectName(u"axWidget") self.axWidget.setProperty("StartConnected", 1) self.gridLayout.addWidget(self.axWidget, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName(u"menubar") self.menubar.setGeometry(QRect(0, 0, 800, 21)) MainWindow.setMenuBar(self.menubar) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName(u"statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) # setupUi def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) self.axWidget.setProperty("ConnectingText", "") self.axWidget.setProperty("DisconnectedText", "") self.axWidget.setProperty("Server", "") self.axWidget.setProperty("UserName", "") # retranslateUi ```
-
@jsulm said in QtAxContainer.QAxWidget can't from RDP control my windows computer:
run it through debugger
yes, i run it through debugger ,but there is no info from debuger,and my Windows task manager has no task that’s about RDP running ,it just show the new Python Task ,i dont know what‘s wrong with it,mybe there is something wrong with QT that can’t Activate RDP Client。
-
@Tian-Sen You should add error handling.
There are https://doc.qt.io/qt-6/qaxbasewidget.html#exception and https://doc.qt.io/qt-6/qaxbasewidget.html#signal signals. Connect slots to them and see what happens. I guess Connect() hangs and since you're calling it in constructor the UI is not initialised properly. -
@jsulm said in QtAxContainer.QAxWidget can't from RDP control my windows computer:
@Tian-Sen You should add error handling.
There are https://doc.qt.io/qt-6/qaxbasewidget.html#exception and https://doc.qt.io/qt-6/qaxbasewidget.html#signal signals. Connect slots to them and see what happens. I guess Connect() hangs and since you're calling it in constructor the UI is not initialised properly.from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtAxContainer import QAxWidget
import sys
class RemoteDesktopWindow(QMainWindow):
def init(self, server_ip, username, password):
super().init()
self.axWidget = QAxWidget("MsRdpClient")
self.axWidget.setControl("{54a2cb42-4f7d-4a07-8c5c-bc0e9e4f3a3a}")self.axWidget.dynamicCall("SetServer", server_ip) self.axWidget.dynamicCall("SetUserName", username) self.axWidget.dynamicCall("SetClearTextPassword", password) self.axWidget.dynamicCall("Connect()") print("连接远程桌面") # 将信号连接到槽以进行错误处理 self.axWidget.exception.connect(self.handle_exception) self.axWidget.signal.connect(self.handle_signal) def handle_exception(self, excep_info): # 在这里处理异常 print("发生异常:", excep_info) def handle_signal(self, signal, argc, argv): # 在这里处理信号 print("收到信号:", signal, argc, argv)
if name == "main":
app = QApplication(sys.argv)
window = RemoteDesktopWindow("1", "DESKTOP-0QR3E2C\testserver", "1234.abcde")
window.show()
sys.exit(app.exec())
i have to set it ,but it don't work ,it just print 连接远程桌面 ,the method handle_exception and handle_signal is not work.