我有一个简单的Qt5项目,有一个按钮和一个文本字段,我也在项目中创建了一个py文件来检查如何从Qt调用python文件中的函数。在
虽然现在我卡住了;我有我的测试cpp.h和测试cpp.cpp,其中我定义了一个字符串和一个函数来打印该字符串;尽管我不确定现在如何调用python文件中的函数,它只打印字符串。在
我想调用Qt函数,并让它调用python文件中的函数;如何做到这一点?在
testcpp.h文件:#ifndef TESTCPP_H
#define TESTCPP_H
#include
#include
class testcpp : public QObject
{
Q_OBJECT
public:
explicit testcpp(QObject *parent = nullptr);
QString getTest_to_print() const;
void setTest_to_print(const QString &value);
signals:
public slots:
private:
QString test_to_print;
};
#endif // TESTCPP_H
在测试cpp.cpp文件:
^{pr2}$
Python文件:# -*- coding: utf-8 -*-
try:
from PySide import QtWidgets
except:
from PyQt5 import QtWidgets
class test_python:
def __init__(self):
def testme(self, string_to_print):
print(string_to_print)