本文整理汇总了C++中PythonQtObjectPtr::evalFile方法的典型用法代码示例。如果您正苦于以下问题:C++ PythonQtObjectPtr::evalFile方法的具体用法?C++ PythonQtObjectPtr::evalFile怎么用?C++ PythonQtObjectPtr::evalFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PythonQtObjectPtr
的用法示例。
在下文中一共展示了PythonQtObjectPtr::evalFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: data
bool CPythonNode::data(QString gate_name, const CConstDataPointer &data)
{
Q_UNUSED(gate_name);
if(data->getType() == "table") {
// Get the table data structured received.
QSharedPointer<const CTableData> p_table = data.staticCast<const CTableData>();
// Create a table data structure to forward.
QSharedPointer<CTableData> result_table = QSharedPointer<CTableData>(
static_cast<CTableData *>(createData("table")));
QString script_name = getConfig().getParameter("input_script")->value.toString();
// Start a new python context independant of any other.
PythonQtObjectPtr module = PythonQt::self()->createUniqueModule();
// Evaluate the user-supplied python script.
module.evalFile(script_name);
// Call the 'main' function of the user script with the received table
// ... and a table that will contatin the results as arguments.
QVariant result = module.call("main",
QVariantList() << QVariant::fromValue(p_table.data())
<< QVariant::fromValue(result_table.data()));
if(result.toBool()) {
commit("out", result_table);
}
return true;
}
else if(data->getType() == "tcpstreams") {
// The TCP Streams data structure.
QSharedPointer<const CTcpStreamsData> p_flows = data.staticCast<const CTcpStreamsData>();
// Create a table data structure to forward.
QSharedPointer<CTableData> result_table = QSharedPointer<CTableData>(
static_cast<CTableData *>(createData("table")));
QString script_name = getConfig().getParameter("input_script")->value.toString();
// Start a new python context independant of any other.
PythonQtObjectPtr module = PythonQt::self()->createUniqueModule();
// Evaluate the user-supplied python script.
module.evalFile(script_name);
// Call the 'main' function of the user script with the received table
// ... and a table that will contatin the results as arguments.
QVariant result = module.call("main",
QVariantList() << QVariant::fromValue(p_flows.data())
<< QVariant::fromValue(result_table.data()));
// If the python script returned true, commit the results' table.
if(result.toBool()) {
commit("out", result_table);
}
return true;
}
return false;
}
示例2: main
int main( int argc, char **argv )
{
QApplication qapp(argc, argv);
PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
PythonQt_QtAll::init();
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
bool showConsole = false;
QStringList files;
for (int i = 1; i < argc; i++) {
QString arg = argv[i];
QString argLower = arg.toLower();
if (argLower == "-console" || argLower == "-c") {
showConsole = true;
} else {
QString file = arg;
QFileInfo info(file);
if (info.exists()) {
files << info.absoluteFilePath();
// add the file's absolute path for local importing
PythonQt::self()->addSysPath(info.absolutePath());
} else {
QMessageBox::warning(NULL, "PyLauncher", QString("File does not exist: %1").arg(file));
}
}
}
PythonQtScriptingConsole console(NULL, mainContext);
Q_FOREACH(QString file, files) {
mainContext.evalFile(file);
}
示例3: main
int main( int argc, char **argv )
{
QApplication qapp(argc, argv);
PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
PythonQt_QtAll::init();
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
PythonQtScriptingConsole console(NULL, mainContext);
// add a QObject to the namespace of the main python context
PyExampleObject example;
mainContext.addObject("example", &example);
mainContext.evalFile(":example.py");
console.show();
return qapp.exec();
}
示例4: main
int main( int argc, char **argv )
{
QApplication qapp(argc, argv);
PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
PythonQtObjectPtr mainContext = PythonQt::self()->getMainModule();
PythonQtScriptingConsole console(NULL, mainContext);
// register the type with QMetaType
qRegisterMetaType<CustomObject>("CustomObject");
// add a wrapper object for the new variant type
PythonQt::self()->registerCPPClass("CustomObject","","example", PythonQtCreateObject<CustomObjectWrapper>);
mainContext.evalFile(":example.py");
console.appendCommandPrompt();
console.show();
return qapp.exec();
}