Hello,
i have written a qml-map widget which gets displayed, but there seems to be an "undefined" object or something like that. I get an access violation exception from sysfer.dll.
I currently don't know where this comes from. Any help would be appreciated!
main.cpp
#include <QtWidgets/QApplication>
#include <MainWindow.h>
int main(int argc, char *argv[])
{
// load resources from binary
// infos: http://doc.qt.io/qt-5/resources.html
Q_INIT_RESOURCE(qmlsources);
MainWindow mw;
mw.show();
return a.exec();
}
#include <QtWidgets/QApplication>
#include <MainWindow.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// load resources from binary
// infos: http://doc.qt.io/qt-5/resources.html
Q_INIT_RESOURCE(qmlsources);
MainWindow mw;
mw.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtWidgets/QWidget>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QLabel>
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
protected:
private slots:
void quit();
private:
void createMenus();
void createActions();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtWidgets/QWidget>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QLabel>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
protected:
void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
private slots:
void quit();
private:
QPushButton *_quit;
QMenu *_fileMenu;
QLabel *_infoLabel;
QAction *_quitAct;
void createMenus();
void createActions();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
MainWindow.cpp:
#include <QDir>
#include <QtWidgets/QWidget>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QLabel>
#include <QtWidgets/QBoxLayout>
#include <QtGui/QContextMenuEvent>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQuickView>
#include <QQuickWidget>
#include "MainWindow.h"
{
// embed resources into binary
// infos: http://doc.qt.io/qt-5/resources.html
Q_INIT_RESOURCE(qmlsources);
this->resize(1024, 768);
createActions();
createMenus();
//WORKS!!!
QQmlEngine *engine = new QQmlEngine(this);
QQuickWidget *view = new QQuickWidget(engine, this);
view
->setSource
(QUrl("qrc:/map.qml"));
this->setCentralWidget(view);
view->setResizeMode(QQuickWidget::SizeRootObjectToView);
}
MainWindow::~MainWindow()
{
}
{
menu.addAction(_quitAct);
menu.exec(event->globalPos());
}
void MainWindow::createMenus()
{
_fileMenu = menuBar()->addMenu(tr("File"));
_fileMenu -> addAction(_quitAct);
}
void MainWindow::createActions()
{
_quitAct
= new QAction(tr
("Quit"),
this);
connect(_quitAct, &QAction::triggered, this, &MainWindow::quit);
}
void MainWindow::quit()
{
// _infoLabel->setText(tr("Invoked <b>File|Quit</b>"));
exit(1);
}
#include <QDir>
#include <QtWidgets/QWidget>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QMenu>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QLabel>
#include <QtWidgets/QBoxLayout>
#include <QtGui/QContextMenuEvent>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQuickView>
#include <QQuickWidget>
#include "MainWindow.h"
MainWindow::MainWindow() : QMainWindow ()
{
// embed resources into binary
// infos: http://doc.qt.io/qt-5/resources.html
Q_INIT_RESOURCE(qmlsources);
this->resize(1024, 768);
createActions();
createMenus();
//WORKS!!!
QQmlEngine *engine = new QQmlEngine(this);
QQuickWidget *view = new QQuickWidget(engine, this);
view->setSource(QUrl("qrc:/map.qml"));
this->setCentralWidget(view);
view->setResizeMode(QQuickWidget::SizeRootObjectToView);
}
MainWindow::~MainWindow()
{
}
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
menu.addAction(_quitAct);
menu.exec(event->globalPos());
}
void MainWindow::createMenus()
{
_fileMenu = menuBar()->addMenu(tr("File"));
_fileMenu -> addAction(_quitAct);
}
void MainWindow::createActions()
{
_quitAct = new QAction(tr("Quit"), this);
connect(_quitAct, &QAction::triggered, this, &MainWindow::quit);
}
void MainWindow::quit()
{
// _infoLabel->setText(tr("Invoked <b>File|Quit</b>"));
exit(1);
}
To copy to clipboard, switch view to plain text mode
map.qml:
import QtQuick 2.3
import QtPositioning 5.6
import QtLocation 5.6
Map {
id: map
width: 640
height:480
plugin: Plugin {
name: "osm"
}
center {
latitude: -27
longitude: 153
}
zoomLevel: 10
gesture.enabled: true
Component.onCompleted: {
console.log("Dimensions: ", width, height)
}
}
import QtQuick 2.3
import QtPositioning 5.6
import QtLocation 5.6
Map {
id: map
width: 640
height:480
plugin: Plugin {
name: "osm"
}
center {
latitude: -27
longitude: 153
}
zoomLevel: 10
gesture.enabled: true
Component.onCompleted: {
console.log("Dimensions: ", width, height)
}
}
To copy to clipboard, switch view to plain text mode
Using VisualStudio2015 Ultimate, compiling as debug mode!
Thanks in advance for any hint or comment!
Bookmarks