简体   繁体   中英

Add MarbleWidget into main window on QT

I'm trying to integrate a MarbleWidget into a QT project. If I only want to show the widget like this:

Marble::MarbleWidget *mapWidget = new Marble::MarbleWidget();
mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
mapWidget->show()

everything is fine. But what I would like to do is integrate the widget into an existing window. What I did is that I added a widget using QtDesigner, promoted the widget to Marble::MarbleWidget then used the following code:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->widget = new Marble::MarbleWidget();
    ui->widget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
    ui->setupUi(this);
}

I can see the widget but no map:

集成时的小部件

and I see the following errors on the console:

QObject::connect: No such signal MarbleWebView::titleChanged(QString) in ~/marble/sources/src/lib/marble/PopupItem.cpp:71
QObject::connect:  (sender name:   'webView')
QObject::connect:  (receiver name: 'titleText')
QObject::connect: No such signal MarbleWebView::urlChanged(QUrl) in ~/marble/sources/src/lib/marble/PopupItem.cpp:72
QObject::connect:  (sender name:   'webView')
QObject::connect: No such signal MarbleWebView::titleChanged(QString) in ~/marble/sources/src/lib/marble/PopupItem.cpp:71
QObject::connect:  (sender name:   'webView')
QObject::connect:  (receiver name: 'titleText')
QObject::connect: No such signal MarbleWebView::urlChanged(QUrl) in ~/marble/sources/src/lib/marble/PopupItem.cpp:72
QObject::connect:  (sender name:   'webView')

What did I do wrong?

When you promote a widget in designer then that widget will be an instance of the class you promoted to.

What you are doing here is create another Marble::Widget and telling that second marble widget to load the data.

The one you promoted is some member of the ui pointer, you need to call the setMapThemeId() on that object.

What Kevin said. Code-wise that would be

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->widget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM