Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从QT creator C++;_Python_C++_Qt_Qt Creator - Fatal编程技术网

Python 从QT creator C++;

Python 从QT creator C++;,python,c++,qt,qt-creator,Python,C++,Qt,Qt Creator,嗨,伙计们。 我需要你的帮助。所以,我正在创建一个qt桌面应用程序,我需要在te项目中从python文件调用函数方法 因此,我的python文件: import logging import os from time import gmtime, strftime class Logger(): LOG_TO_FILE=True @staticmethod def currentTime():

嗨,伙计们。 我需要你的帮助。所以,我正在创建一个qt桌面应用程序,我需要在te项目中从python文件调用函数方法

因此,我的python文件:

    import logging
import os
from time import gmtime, strftime

class Logger():

    LOG_TO_FILE=True

    @staticmethod                        
    def currentTime():
        return strftime("%Y-%m-%d %H:%M:%S", gmtime())

    @staticmethod                        
    def log(msg):    
        print msg
        Logger.saveToFile(msg)

    @staticmethod                        
    def info(label, msg):    
        msg = "%s Info  : [%s] -> %s" % (Logger.currentTime(), label, msg)      
        Logger.saveToFile(msg)
        print msg

    @staticmethod                        
    def debug(label, msg):
        msg =  "%s Debug : [%s] -> %s" % (Logger.currentTime(), label, msg)      
        Logger.saveToFile(msg)
        print msg

    @staticmethod                        
    def warning(label, msg):
        msg = "%s Warn  : [%s] -> %s" % (Logger.currentTime(), label, msg)      
        Logger.saveToFile(msg)
        print msg

    @staticmethod                        
    def critical(label, msg):
        msg = "%s Critic : [%s] -> %s" % (Logger.currentTime(), label, msg)      
        Logger.saveToFile(msg)
        print msg

    @staticmethod                        
    def error(label, msg):
        msg = "%s Error : [%s] -> %s" % (Logger.currentTime(), label, msg)      
        Logger.saveToFile(msg)
        print msg
        #log.critical(msg)

    @staticmethod                        
    def data(label, msg):    
        msg = "%s Data  : [%s] -> \t%s" % (Logger.currentTime(), label, msg)      
        Logger.saveToFile(msg)
        print msg

    @staticmethod                        
    def saveToFile(message):
        if Logger.LOG_TO_FILE is True:

            if os.path.exists('/var/log/iot-pi') is not True:
                os.makedirs('/var/log/iot-pi')

            try:
                filePath='/var/log/iot-pi/main.log'
                f = open(filePath,'a')
                f.write(message + '\n')
                f.close()

                bytes = os.path.getsize(filePath)
                if bytes >= 10000000:
                    os.remove(filePath)
                    Logger.info("SYSTEM", "Log file removed")
            except Exception as inst:
                print "save to file error (%s)" % inst


if __name__ == "__main__":
    Logger.info("Test", "Message test")
我的主要cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[]) {
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    //call Logger.py here ?? it's possible ?

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec(); }
#包括
#包括
int main(int argc,char*argv[]){
QCoreApplication::setAttribute(Qt::AA_enableHighdDiscaling);
QGUI应用程序应用程序(argc、argv);
//在这里调用Logger.py??有可能吗?
qqmlaplicationengine;
engine.load(QUrl(QStringLiteral(“qrc:/main.qml”));
if(engine.rootObjects().isEmpty())
返回-1;
返回app.exec();}
<> P>有函数获取模式,例如C++中QT后端的警告方法? 我已经将python库添加到项目中。我需要“仅”从py文件获取def。我不能使用其他文件,我需要调用python文件

我使用qt5.11。
谢谢。

看看这个StackOverflow:不,我以前从未见过,我现在看到了。如果您的工具仅在linux中运行,您可以使用DBus…。@Mr.Developer请参见