嗨伙计们。
我需要你的帮助。所以,我正在创建一个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
^{pr2}$
<> P>有函数获取模式,例如C++中QT后端的警告方法?
我已经在项目中添加了python库。我只需要从py文件中获取def。我不能使用其他文件,我需要调用python文件。在
我用qt5.11。
谢谢。在