I have a simple Qt5 project with a button and a text field, I did create also a py file in the project to check how to call functions in python files, from Qt.
Although now I am stuck; I have my testcpp.h and testcpp.cpp, where I define a string and a function to print that string; although I am not sure how do I call now the function in the python file, which simply print a string.
I want to call the Qt function, and have it call the function in the python file; how do you do that?
testcpp.h file:
#ifndef TESTCPP_H
#define TESTCPP_H
#include <QObject>
#include <QString>
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
testcpp.cpp file:
#include "testcpp.h"
testcpp::testcpp(QObject *parent) : QObject(parent)
{
}
QString testcpp::getTest_to_print() const
{
return test_to_print;
}
void testcpp::setTest_to_print(const QString &value)
{
test_to_print = value;
}
void testcpp::PrintViaPython(QString &test_to_print)
{
}
Python file:
# -*- 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)