当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 1

Admin/GETTAOBAO
暂停

forked from EVA/GETTAOBAO
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pythonTest.cpp 7.88 KB
一键复制 编辑 原始数据 按行查看 历史
kiki 提交于 2019-05-31 09:10 . Signed-off-by: kiki 6626160@qq.com
#include "pythonTest.h"
#include <QDebug>
#include <QMessageBox>
pythonTest::pythonTest():pModule(NULL)
{
// Py_SetPythonHome(L"C:\\Programs\\Python\\Python37-32");
Py_Initialize();
// QMessageBox::information(NULL, "Title", "1", QMessageBox::Yes, QMessageBox::Yes);
if (!Py_IsInitialized()) {
qDebug() << "inititalize failed";
}
else {
qDebug() << "inititalize success";
}
// QMessageBox::information(NULL, "Title", "python successful", QMessageBox::Yes, QMessageBox::Yes);
PyRun_SimpleString("import xlrd");
PyRun_SimpleString("import xlwt");
PyRun_SimpleString("import json");
PyRun_SimpleString("import ExcelParserTIF");
PyRun_SimpleString("import string");
PyRun_SimpleString("import jieba");
PyRun_SimpleString("import sqlite3");
pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
QMessageBox::information(NULL, "Title", "can not import python module file", QMessageBox::Yes, QMessageBox::Yes);
}
}
pythonTest::~pythonTest()
{
if(pModule)
Py_DECREF(pModule);
Py_Finalize();
}
QString pythonTest::getExcelInfo( QString& strFileName) const
{
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
return "FAIL";
}
else {
qDebug() << "inititalize success";
}
// PyObject * pModule = NULL;
PyObject * pFunc = NULL;
//pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "processdo");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("sss", "1","3","4"));
int a;
int b;
int size = PyDict_Size(pRet);
//char *ss =new char [1000];
if (pRet)
{
qDebug() << "分析数据成功";
// PyArg_ParseTuple(pRet, "is", &a,ss);
//strGetInfo = s;
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
}
}
// Py_Finalize();
return strGetInfo;
}
QString pythonTest::getExcel( QString &str) const
{
// Py_SetPythonHome(L"C:\\Programs\\Python\\Python37-32");
// Py_Initialize();
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
return "FAIL";
}
else {
qDebug() << "inititalize success";
}
PyObject * pFunc = NULL;
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "getlist");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("(s)", str.toStdString().c_str()));
int a;
int b;
int size = PyDict_Size(pRet);
char *ss =new char [1000];
if (pRet)
{
qDebug() << "分析数据成功";
PyArg_ParseTuple(pRet, "s", &ss);
strGetInfo = ss;
Py_DECREF(pRet);
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
Py_DECREF(pFunc);
}
}
// Py_Finalize();
return strGetInfo;
}
QString pythonTest::save( QString &str)
{
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
Py_Initialize();
PyRun_SimpleString("import xlrd");
PyRun_SimpleString("import xlwt");
PyRun_SimpleString("import json");
PyRun_SimpleString("import ExcelParserTIF");
PyRun_SimpleString("import string");
PyRun_SimpleString("import jieba");
PyRun_SimpleString("import sqlite3");
pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
QMessageBox::information(NULL, "Title", "can not import python module file", QMessageBox::Yes, QMessageBox::Yes);
}
//return "FAIL";
}
else {
qDebug() << "inititalize success";
}
PyObject * pFunc = NULL;
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "save");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("(s)", str.toStdString().c_str()));
int a;
int b;
// int size = PyDict_Size(pRet);
char *ss ;
if (pRet)
{
qDebug() << "分析数据成功";
// int kiki = PyArg_Parse(pRet, "s", &ss);
strGetInfo = "分析数据成功";
//qDebug() <<"dddd"<<strGetInfo;
Py_DECREF(pRet);
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
Py_DECREF(pFunc);
}
}
return strGetInfo;
};
QString pythonTest::smil(QString title, QString path ,int n)
{
QString strGetInfo;
if (!Py_IsInitialized()) {
printf("inititalize failed");
qDebug() << "inititalize failed";
return "FAIL";
}
else {
qDebug() << "inititalize success";
}
// PyObject * pModule = NULL;
PyObject * pFunc = NULL;
// pModule = PyImport_ImportModule("TIF");
if (!pModule)
{
qDebug() << "can not import python module file";
}
else
{
// PyRun_SimpleString("import json");
// PyRun_SimpleString("from collections import OrderedDict");
pFunc = PyObject_GetAttrString(pModule, "smil");
if(pFunc)
{
PyObject* pRet = PyEval_CallObject(pFunc, Py_BuildValue("(s,s,i)", path.toStdString().c_str(),
title.toStdString().c_str(),n));
int a;
int b;
// int size = PyDict_Size(pRet);
char *ss ;
if (pRet)
{
qDebug() << "分析数据成功";
int kiki = PyArg_Parse(pRet, "s", &ss);
strGetInfo = ss;
//qDebug() <<"dddd"<<strGetInfo;
Py_DECREF(pRet);
}
else
{
qDebug() << "error";
strGetInfo ="打开的文件不是excel表,excel请用后缀名是.xlxs的文件。";
}
// ui->textEditLog->setPlainText(s);
Py_DECREF(pFunc);
}
}
// Py_Finalize();
return strGetInfo;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/perfect_1_748750778/GETTAOBAO.git
git@gitee.com:perfect_1_748750778/GETTAOBAO.git
perfect_1_748750778
GETTAOBAO
GETTAOBAO
master

搜索帮助