Qt-jambi-interest Archive, April 2007
Invoking a modeless Jambi top level widget from Swing
Message 1 in thread
Hi,
I've only just started using Jambi so apologies if this is a stupid
question or I'm missing something obvious.
I'd like to display a top level Jambi dialog from Swing code. If I use a
modal dialog everything is fine, but I'd rather it was modeless. If I don't
use QDialog::exec() how and where do I create a Qt Jambi event loop that
won't lock out the Swing event dispatch thread? Is such a thing possible or
advisable?
Thanks,
Ian
Message 2 in thread
Ian.Soanes@xxxxxxxxxxxxxx wrote:
> Hi,
>
> I've only just started using Jambi so apologies if this is a stupid
> question or I'm missing something obvious.
>
> I'd like to display a top level Jambi dialog from Swing code. If I use a
> modal dialog everything is fine, but I'd rather it was modeless. If I don't
> use QDialog::exec() how and where do I create a Qt Jambi event loop that
> won't lock out the Swing event dispatch thread? Is such a thing possible or
> advisable?
Qt requires you to run the application in the main thread. On Windows
and X11 it is usually fine to have QApplication in any thread, but its
not advisable. On Mac OS X, you initialize/exec your QApplication from
the main thread.
So, what that means is that to get Swing / Qt running together you need
to add something along the lines of...
public static void main(String args[]) {
QApplication.initialize(args);
// Start your Swing app
SwingPartOfApp swing = new SwingPartOfApp();
// Start the Qt part of your application.
QtPartOfApp qt = new QtPartOfApp();
// Spin the Qt eventloop in the main thread.
QApplication.exec();
}
Note that if you plan on opening a Qt widget from the swing dispatch
thread, you have to do that by posting a message to the QApplication
thread, such as
public void actionPerformed() {
QApplication.invokeLater(new Runnable() {
MyQMainWindow d = new MyQMainWindow();
d.show();
});
}
Alternativly using a queued connection from your swing class to the Qt
Class..
-
best regards,
Gunnar