16,213
社区成员
发帖
与我相关
我的任务
分享
QT += widgets
SOURCES += \
main.cpp
INCLUDEPATH += -I F:\Python35\include\
LIBS += F:\Python35\libs\ -lpython35
DISTFILES += \
B.py
CONFIG += no_keywords
#include <QCoreApplication>
#include "Python.h"
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Py_Initialize();
if (!Py_IsInitialized())
{
return -1;
}
PyObject* pModule = PyImport_ImportModule("B");
if (!pModule) {
qDebug() << "Cant open python file!";
return -1;
}
PyObject* pFunhello= PyObject_GetAttrString(pModule,"hello");
if(!pFunhello) {
qDebug() << "Get function hello failed";
return -1;
}
PyObject_CallFunction(pFunhello,NULL);
Py_Finalize();
return a.exec();
}
def hello():
print("hello")