Skip to content

Commit

Permalink
Add method resetErrorFlag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jcfr committed Oct 17, 2012
1 parent 2114405 commit a386dc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/PythonQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ PythonQtObjectPtr PythonQt::importModule(const QString& name)

QVariant PythonQt::evalCode(PyObject* object, PyObject* pycode) {
QVariant result;
this->resetErrorFlag();
if (pycode) {
PyObject* dict = NULL;
if (PyModule_Check(object)) {
Expand Down Expand Up @@ -703,6 +704,7 @@ QVariant PythonQt::evalScript(PyObject* object, const QString& script, int start
QVariant result;
PythonQtObjectPtr p;
PyObject* dict = NULL;
this->resetErrorFlag();
if (PyModule_Check(object)) {
dict = PyModule_GetDict(object);
} else if (PyDict_Check(object)) {
Expand All @@ -722,6 +724,7 @@ QVariant PythonQt::evalScript(PyObject* object, const QString& script, int start
void PythonQt::evalFile(PyObject* module, const QString& filename)
{
PythonQtObjectPtr code = parseFile(filename);
this->resetErrorFlag();
if (code) {
evalCode(module, code);
} else {
Expand All @@ -733,6 +736,7 @@ PythonQtObjectPtr PythonQt::parseFile(const QString& filename)
{
PythonQtObjectPtr p;
p.setNewRef(PythonQtImport::getCodeFromPyc(filename));
this->resetErrorFlag();
if (!p) {
handleError();
}
Expand Down Expand Up @@ -1022,6 +1026,7 @@ QVariant PythonQt::call(PyObject* callable, const QVariantList& args)
QVariant r;
PythonQtObjectPtr result;
result.setNewRef(callAndReturnPyObject(callable, args));
this->resetErrorFlag();
if (result) {
r = PythonQtConv::PyObjToQVariant(result);
} else {
Expand Down Expand Up @@ -1243,6 +1248,14 @@ bool PythonQt::errorOccured()const
return PythonQt::priv()->_ErrorOccured;
}

void PythonQt::resetErrorFlag()
{
if (PythonQt::self())
{
PythonQt::priv()->_ErrorOccured = false;
}
}

void PythonQt::addSysPath(const QString& path)
{
PythonQtObjectPtr sys;
Expand Down Expand Up @@ -1568,6 +1581,7 @@ PythonQtInstanceWrapper* PythonQtPrivate::findWrapperAndRemoveUnused(void* obj)
PythonQtObjectPtr PythonQtPrivate::createModule(const QString& name, PyObject* pycode)
{
PythonQtObjectPtr result;
PythonQt::self()->resetErrorFlag();
if (pycode) {
result.setNewRef(PyImport_ExecCodeModule((char*)name.toLatin1().data(), pycode));
} else {
Expand Down Expand Up @@ -1747,4 +1761,4 @@ void PythonQtPrivate::shellClassDeleted( void* shellClass )
// if the wrapper is a QObject, we do not handle this here,
// it will be handled by the QPointer<> to the QObject, which becomes NULL
// via the QObject destructor.
}
}
4 changes: 4 additions & 0 deletions src/PythonQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ class PYTHONQT_EXPORT PythonQt : public QObject {
//! return \a True if \a handleError() has been called and an error occured.
bool errorOccured()const;

//! reset error flag. After calling this, errorOccured() will return False.
//! \sa PythonQt::errorOccured()
void resetErrorFlag();

//! set a callback that is called when a QObject with parent == NULL is wrapped by pythonqt
void setQObjectWrappedCallback(PythonQtQObjectWrappedCB* cb);
//! set a callback that is called when a QObject with parent == NULL is no longer wrapped by pythonqt
Expand Down

0 comments on commit a386dc6

Please sign in to comment.