You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Squish IDE的Python环境中使用PyQt5创建测试信息外部界面的可行性及导入报错问题咨询

Can I use PyQt5 to create an external GUI in Squish IDE for Qt app testing?

Yes, absolutely—you can create an external GUI with PyQt5 alongside your Squish Python test cases. The DLL error you're hitting is a common architecture mismatch issue, not a fundamental limitation of Squish. Let's break down the problem and fix it:

Why the ImportError happens

The error Detail ImportError: DLL load failed while importing QtWidgets: %1 non è un'applicazione di Win32 valida. translates to "not a valid Win32 application". This almost always means:

  • Squish IDE uses its own bundled Python interpreter (either 32-bit or 64-bit)
  • You installed PyQt5 for a different architecture (e.g., 64-bit PyQt5 with 32-bit Squish Python)
    The two environments are incompatible, so the DLL can't load.

Fix 1: Install PyQt5 for Squish's bundled Python

Squish doesn't use your system's Python—you need to install PyQt5 directly into Squish's own Python environment:

  1. Check Squish Python's architecture:
    Create a quick test case in Squish and run this code:
    import sys
    print("64-bit Python" if sys.maxsize > 2**32 else "32-bit Python")
    
  2. Install matching PyQt5:
    Locate Squish's Python executable. On Windows, it's typically in a path like C:\Squish for Qt [VERSION]\python\python.exe.
    Open Command Prompt and run:
    "C:\Path\To\Squish\python\python.exe" -m pip install pyqt5
    
    This installs a PyQt5 version that matches Squish's Python architecture, resolving the DLL error.

Fix 2: Use a subprocess for the external GUI (safer option)

If you don't want to modify Squish's bundled environment, or if you run into Qt version conflicts between Squish and PyQt5, use a separate subprocess for your GUI. This keeps your test logic and GUI isolated, avoiding interference with Squish's runtime:

  1. Create a standalone PyQt5 GUI script (e.g., test_monitor.py):
    from PyQt5 import QtWidgets, QtCore
    import sys
    import json
    
    class TestMonitor(QtWidgets.QMainWindow):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("Test Execution Monitor")
            self.log_view = QtWidgets.QTextEdit()
            self.setCentralWidget(self.log_view)
            # Set up a timer to read messages from Squish
            self.stdin_timer = QtCore.QTimer()
            self.stdin_timer.timeout.connect(self.read_test_updates)
            self.stdin_timer.start(100)
    
        def read_test_updates(self):
            while sys.stdin.ready():
                line = sys.stdin.readline().strip()
                if not line:
                    continue
                try:
                    update = json.loads(line)
                    self.log_view.append(f"[{update['status']}] {update['test_case']}: {update['message']}")
                except json.JSONDecodeError:
                    pass
    
    if __name__ == "__main__":
        app = QtWidgets.QApplication(sys.argv)
        window = TestMonitor()
        window.show()
        sys.exit(app.exec_())
    
  2. Launch the GUI from your Squish test case:
    Use subprocess to start the GUI and send test updates via stdin:
    import subprocess
    import json
    import os
    import sys
    
    # Start the external GUI process
    gui_script_path = os.path.join(os.path.dirname(__file__), "test_monitor.py")
    gui_process = subprocess.Popen(
        [sys.executable, gui_script_path],
        stdin=subprocess.PIPE,
        text=True
    )
    
    # Helper function to send updates
    def send_test_update(status, test_case, message):
        update = {
            "status": status,
            "test_case": test_case,
            "message": message
        }
        gui_process.stdin.write(json.dumps(update) + "\n")
        gui_process.stdin.flush()
    
    # Example usage in your test
    send_test_update("START", "LoginTest", "Beginning login validation")
    # ... run test steps ...
    send_test_update("PASS", "LoginTest", "Login succeeded with valid credentials")
    

Key Notes

  • If you choose to import PyQt5 directly in Squish, ensure PyQt5's Qt version is close to the one Squish uses (check Squish's documentation for your version) to avoid library conflicts.
  • The subprocess approach is generally safer because it isolates your GUI from Squish's testing runtime, preventing unexpected behavior in your test execution.

内容的提问来源于stack exchange,提问作者Andrea Valitutto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 16:58:11