#include <QApplication>
#include "testexe_dll.h"
#include "iostream"
#ifdef __cplusplus
extern "C" {
#endif
TESTEXE_DLL_EXPORT int addFunc(int a, int b)
{
int result = a + b;
std::cout<<"-----------";
return result;
}
TESTEXE_DLL_EXPORT void show_dialog(TestExe_dll *dll)
{
dll->showDialog();
}
TESTEXE_DLL_EXPORT QWidget* get_dialog(TestExe_dll *dll)
{
return dll->getDialog();
}
TESTEXE_DLL_EXPORT void init(TestExe_dll *dll)
{
dll->initWin();
}
#ifdef __cplusplus
}
#endif
QWidget* g_widget;
Form *dlgForm = NULL;
int argc;
char* argv[] = {};
QApplication a(argc, argv);
TestExe_dll::TestExe_dll()
{
}
int TestExe_dll::showDialog()
{
dlgForm->show();
return a.exec();
}
void TestExe_dll::initWin()
{
dlgForm = new Form();
g_widget = dlgForm;
dlgForm->hide();
}
QWidget *TestExe_dll::getDialog()
{
return g_widget;
}
除第三个方法以外,其他方法python可以调用成功。
问题:python如何接收QWidget指针类型?(python 零基础)
ps:QWidget是Qt中的窗口类,我将Qt窗口返回出去,供外部获取窗口内的控件。
以下是调用过程及报错信息:AttributeError: 'int' object has no attribute 'children'
Children()是Qt中QWidget中的方法,通过get_dialog()返回QWidget给widget,widget为int类型,故报错int中没有children属性,我需要一个QWidget来接收get_dialog(),但是我不知道在python中如何操作。
from PyQt6.QtWidgets import QApplication,QMainWindow,QWidget,QPushButton
from ctypes import *
import sys
from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6.QtWidgets import QApplication
if __name__ == "__main__":
App = QApplication(sys.argv) # 创建QApplication对象,作为GUI主程序入口
dll_path = "E:\\testQtProject\\testExe_dll\\bin\\testExe_dll.dll"
lib = cdll.LoadLibrary(dll_path) # 加载Qt动态库
lib.init() # 库初始化
widget = lib.get_dialog() # 获取窗口,返回值为QWidget*
print(widget)
listW = widget.children()
print(listW)
widget.show()
sys.exit(App.exec()) # 循环中等待退出程序
报错信息:
Traceback (most recent call last):
File "C:\Users\dell\PycharmProjects\untitled\testQt.py", line 17, in
listW = widget.children()
AttributeError: 'int' object has no attribute 'children'