0

I want to call a wrapped C++ function from a python script which is not returning immediately (in detail: it is a function which starts a QApplication window and the last line in that function is QApplication->exec()). So after that function call I want to move on to my next line in the python script but on executing this script and the previous line it hangs forever.

In contrast when I manually type my script line for line in the python command line I can go on to my next line after pressing enter a second time on the non-returning function call line.

So how to solve the issue when executing the script?

Thanks!!

Edit:

My python interpreter is embedded in an application. I want to write an extension for this application as a separate Qt4 window. All the python stuff is only for make my graphical plugin accessible per script (per boost.python wrapping).

My python script:

import imp
import os
Plugin = imp.load_dynamic('Plugin', os.getcwd() + 'Plugin.dll')

qt = Plugin.StartQt4()     # it hangs here when executing as script
pl = PluginCPP.PluginCPP() # Creates a QMainWindow
pl.ShowWindow()            # shows the window

The C++ code for the Qt start function looks like this:

class StartQt4
{
public:
  StartQt4()
  {
    int i = 0;
    QApplication* qapp = new QApplication(i, NULL);
    qapp->exec();
  }
};
0

3 Answers 3

2

Use a thread (longer example here):

from threading import Thread

class WindowThread(Thread):
    def run(self):
        callCppFunctionHere()

WindowThread().start()
Sign up to request clarification or add additional context in comments.

1 Comment

I think this would work great but not in my case. Everything should run in the same thread.
1

QApplication::exec() starts the main loop of the application and will only return after the application quits. If you want to run code after the application has been started, you should resort to Qt's event handling mechanism.

From http://doc.trolltech.com/4.5/qapplication.html#exec :

To make your application perform idle processing, i.e. executing a special function whenever there are no pending events, use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents().

Comments

0

I assume you're already using PyQT?

1 Comment

No. I only use python to start my Qt window. The c++ code for this is wrapped to python with boost.python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.