[Qt-interest] Gtk+ and Qt migration/integration
Vadim Godunko
vgodunko at rostel.ru
Fri Feb 20 22:22:19 CET 2009
Vadim Godunko wrote:
>
> I have a lot of Gtk+ code and want to migrate to Qt. Is it possible to
> use Gtk+ code inside Qt application?
Thanks all for help! It seems possible to use Gtk+ and Qt in the same
application only on X11 platforms. Here is my test program. It creates
combination of the Gtk+/Qt main window and push button depending from
values of the MAINWINDOW_IS_QT and EMBEDDED_IS_QT macros. Unfortunately,
Qt's main window seems unable to embed Gtk+'s push button.
#include <gtk/gtk.h>
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QX11EmbedContainer>
#include <QX11EmbedWidget>
#define MAINWINDOW_IS_QT true
#define EMBEDDED_IS_QT true
void create_qt_embed(long id)
{
QX11EmbedWidget* plug = new QX11EmbedWidget;
plug->embedInto(id);
QPushButton* button = new QPushButton("My Label", plug);
plug->show();
}
void create_gtk_plug(long id)
{
GtkWidget* plug = gtk_plug_new(id);
gtk_widget_show(plug);
GtkWidget* button = gtk_button_new_with_label("My Label");
gtk_widget_show(button);
gtk_container_add(GTK_CONTAINER(plug), button);
}
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);
QApplication app(argc, argv);
if (MAINWINDOW_IS_QT)
{
QMainWindow* main_window = new QMainWindow;
QX11EmbedContainer* container = new QX11EmbedContainer;
main_window->setCentralWidget(container);
if (EMBEDDED_IS_QT)
{
create_qt_embed(container->winId());
} else
{
create_gtk_plug(container->winId());
}
main_window->show();
QApplication::exec();
} else
{
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show(window);
GtkWidget* container = gtk_socket_new();
gtk_widget_show(container);
gtk_container_add(GTK_CONTAINER(window), container);
if (EMBEDDED_IS_QT)
{
create_qt_embed(gtk_socket_get_id(GTK_SOCKET(container)));
} else
{
create_gtk_plug(gtk_socket_get_id(GTK_SOCKET(container)));
}
gtk_main();
}
return 0;
}
More information about the Qt-interest-old
mailing list