1
1
#include < PythonQt.h>
2
2
#include < QtGui>
3
+ #include " QFileImportInterface.h"
4
+
3
5
int main (int argc, char * argv[]) {
4
6
QApplication app (argc, argv);
5
7
PythonQt::init ();
6
8
PythonQtObjectPtr mainModule = PythonQt::self ()->getMainModule ();
9
+ mainModule.evalScript (QString (" import sys\n " ));
7
10
Q_ASSERT (!mainModule.isNull ());
8
11
{
9
12
// evaluate a python file embedded in executable as resource:
@@ -17,10 +20,22 @@ int main (int argc, char* argv[]) {
17
20
// tag goes out of scope, reference count decremented.
18
21
}
19
22
qDebug () << " test1" ;
23
+ /*
24
+ {
25
+ // Allow the python system path to recognize QFile paths in the sys.path
26
+ QFileImportInterface qfii;
27
+ // append the Qt resource root directory to the sys.path
28
+ mainModule.evalScript("sys.path.append(':')\n");
29
+ mainModule.evalScript("import eyed3tagger\n");
30
+ PythonQtObjectPtr tag = mainModule.evalScript("eyed3tagger.EyeD3Tagger()\n", Py_eval_input);
31
+ Q_ASSERT(!tag.isNull());
32
+ tag.call("setFileName", QVariantList() << "t.mp3");
33
+ QVariant fn = tag.call("fileName", QVariantList());
34
+ Q_ASSERT(fn.toString() == QString("t.mp3"));
35
+ }
36
+ qDebug() << "test2"; */
20
37
{ // alternative using import and loading it as a real module from sys.path
21
38
// import sys first
22
- mainModule.evalScript (QString (" import sys\n " ));
23
- // append the current directory to the sys.path
24
39
mainModule.evalScript (QString (" sys.path.append('%1')\n " ).arg (QDir::currentPath ()));
25
40
mainModule.evalScript (" import eyed3tagger\n " );
26
41
PythonQtObjectPtr tag = mainModule.evalScript (" eyed3tagger.EyeD3Tagger()\n " , Py_eval_input);
@@ -29,7 +44,6 @@ int main (int argc, char* argv[]) {
29
44
QVariant fn = tag.call (" fileName" , QVariantList ());
30
45
Q_ASSERT (fn.toString () == QString (" t.mp3" ));
31
46
}
32
-
33
47
qDebug () << " finished" ;
34
48
return 0 ;
35
49
}
0 commit comments