Skip to content

Commit a386dc6

Browse files
committed
Add method resetErrorFlag
This method should be called before any piece of code where handleError is called in case of error. It will ensure the _ErrorOccured is reset to false.
1 parent 2114405 commit a386dc6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/PythonQt.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ PythonQtObjectPtr PythonQt::importModule(const QString& name)
675675

676676
QVariant PythonQt::evalCode(PyObject* object, PyObject* pycode) {
677677
QVariant result;
678+
this->resetErrorFlag();
678679
if (pycode) {
679680
PyObject* dict = NULL;
680681
if (PyModule_Check(object)) {
@@ -703,6 +704,7 @@ QVariant PythonQt::evalScript(PyObject* object, const QString& script, int start
703704
QVariant result;
704705
PythonQtObjectPtr p;
705706
PyObject* dict = NULL;
707+
this->resetErrorFlag();
706708
if (PyModule_Check(object)) {
707709
dict = PyModule_GetDict(object);
708710
} else if (PyDict_Check(object)) {
@@ -722,6 +724,7 @@ QVariant PythonQt::evalScript(PyObject* object, const QString& script, int start
722724
void PythonQt::evalFile(PyObject* module, const QString& filename)
723725
{
724726
PythonQtObjectPtr code = parseFile(filename);
727+
this->resetErrorFlag();
725728
if (code) {
726729
evalCode(module, code);
727730
} else {
@@ -733,6 +736,7 @@ PythonQtObjectPtr PythonQt::parseFile(const QString& filename)
733736
{
734737
PythonQtObjectPtr p;
735738
p.setNewRef(PythonQtImport::getCodeFromPyc(filename));
739+
this->resetErrorFlag();
736740
if (!p) {
737741
handleError();
738742
}
@@ -1022,6 +1026,7 @@ QVariant PythonQt::call(PyObject* callable, const QVariantList& args)
10221026
QVariant r;
10231027
PythonQtObjectPtr result;
10241028
result.setNewRef(callAndReturnPyObject(callable, args));
1029+
this->resetErrorFlag();
10251030
if (result) {
10261031
r = PythonQtConv::PyObjToQVariant(result);
10271032
} else {
@@ -1243,6 +1248,14 @@ bool PythonQt::errorOccured()const
12431248
return PythonQt::priv()->_ErrorOccured;
12441249
}
12451250

1251+
void PythonQt::resetErrorFlag()
1252+
{
1253+
if (PythonQt::self())
1254+
{
1255+
PythonQt::priv()->_ErrorOccured = false;
1256+
}
1257+
}
1258+
12461259
void PythonQt::addSysPath(const QString& path)
12471260
{
12481261
PythonQtObjectPtr sys;
@@ -1568,6 +1581,7 @@ PythonQtInstanceWrapper* PythonQtPrivate::findWrapperAndRemoveUnused(void* obj)
15681581
PythonQtObjectPtr PythonQtPrivate::createModule(const QString& name, PyObject* pycode)
15691582
{
15701583
PythonQtObjectPtr result;
1584+
PythonQt::self()->resetErrorFlag();
15711585
if (pycode) {
15721586
result.setNewRef(PyImport_ExecCodeModule((char*)name.toLatin1().data(), pycode));
15731587
} else {
@@ -1747,4 +1761,4 @@ void PythonQtPrivate::shellClassDeleted( void* shellClass )
17471761
// if the wrapper is a QObject, we do not handle this here,
17481762
// it will be handled by the QPointer<> to the QObject, which becomes NULL
17491763
// via the QObject destructor.
1750-
}
1764+
}

src/PythonQt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
484484
//! return \a True if \a handleError() has been called and an error occured.
485485
bool errorOccured()const;
486486

487+
//! reset error flag. After calling this, errorOccured() will return False.
488+
//! \sa PythonQt::errorOccured()
489+
void resetErrorFlag();
490+
487491
//! set a callback that is called when a QObject with parent == NULL is wrapped by pythonqt
488492
void setQObjectWrappedCallback(PythonQtQObjectWrappedCB* cb);
489493
//! set a callback that is called when a QObject with parent == NULL is no longer wrapped by pythonqt

0 commit comments

Comments
 (0)