Include Qt ui file in executable using pyinstaller
pyinstaller.exe --onefile --add-data="visu.ui;." visu.py
References
https://stackoverflow.com/questions/60509042/python-include-ui-file-in-executable-using-pyinstaller
pyinstaller.exe --onefile --add-data="visu.ui;." visu.py
References
https://stackoverflow.com/questions/60509042/python-include-ui-file-in-executable-using-pyinstaller
import sys import os from PySide2.QtWidgets import QApplication, QWidget, QPushButton from PySide2.QtCore import QFile from PySide2.QtUiTools import QUiLoader class main(QWidget): def __init__(self): super(main, self).__init__() self.load_ui() def load_ui(self): loader = QUiLoader() path = os.path.join(os.path.dirname(__file__), "form.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) self.window:QWidget = loader.load(ui_file, self) ui_file.close() # pushButton is the name of button control self.pushButton:QPushButton = self.window.findChild(QPushButton,"pushButton") self.pushButton.clicked.connect(self.clicked) def clicked(self): print("Hello") if __name__ == "__main__": app = QApplication([]) widget = main() widget.show() sys.exit(app.exec_())
References
https://www.blog.pythonlibrary.org/2018/05/30/loading-ui-files-in-qt-for-python/
import sys import os from PySide2.QtWidgets import QApplication, QWidget from PySide2.QtCore import QFile from PySide2.QtUiTools import QUiLoader class main(QWidget): def __init__(self): super(main, self).__init__() self.load_ui() def load_ui(self): loader = QUiLoader() path = os.path.join(os.path.dirname(__file__), "form.ui") ui_file = QFile(path) ui_file.open(QFile.ReadOnly) loader.load(ui_file, self) ui_file.close() if __name__ == "__main__": app = QApplication([]) widget = main() widget.show() sys.exit(app.exec_())
Add to CMake file :
find_package(Qt5Core REQUIRED) qt5_use_modules(project01 Core)
References :
http://stackoverflow.com/questions/34587878/how-to-configure-cmake-in-clion-to-work-with-qt5-5-1-open-source-sdk