-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin cannot be loaded for module "Box2D": Namespace 'Box2D' has already been used for type registration #122
Comments
Hi, I am loading the static lib like this: #include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <box2dplugin.h>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
Box2DPlugin plugin;
plugin.registerTypes("Box2DStatic");
engine.load(QUrl(QStringLiteral("qrc:/ui.qml")));
return app.exec();
} And I had to use the following import statement: import Box2DStatic 2.0 I have prepared a repo which uses a static lib here: Please try and compile the repo. If you can not get your code to work, come back and show more code. Greetings, |
Somehow my comment above is not showing the includes properly: #include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <box2dplugin.h> |
@ThomasVogelpohl You should use fencing to include code. Add |
Well, the problem is gone, but can't perform the qml file yet. Here my main.qml code: import QtQuick 2.9
import Box2DStatic 2.0
import "./shared"
Rectangle {
property var jsonPyr: [{count: 10, color: 'blue', startx: 100, starty: 510}, {count: 9, color: 'brown', startx: 123, starty: 480}, {count: 8, color: 'blue', startx: 145, starty: 450}, {count: 7, color: 'green', startx: 168, starty: 420}, {count: 6, color: 'yellow', startx: 191, starty: 390}, {count: 5, color: 'brown', startx: 214, starty: 360}, {count: 4, color: 'blue', startx: 237, starty: 330}, {count: 3, color: 'green', startx: 260, starty: 300}, {count: 2, color: 'pink', startx: 283, starty: 270}, {count: 1, color: 'yellow', startx: 306, starty: 240}]
id: root
width: 800
height: 600
focus: true
color: "black";
World { id: physicsWorld }
Component {
id: boxChar
Item {
id: mario
width: 30
height: 80
BoxBody {
id: body
world: physicsWorld
target: mario
bodyType: Body.Dynamic
density: 1
friction: 1
restitution: 0.3
width: mario.width
height: mario.height
}
Image {
anchors.fill: parent
anchors.margins: -1
source: "images/super_mario.png"
}
}
}
Column {
id: rectCol
Repeater {
id: repeater1
model: jsonPyr
Row {
id: rectRow
property string rectColor: modelData.color
property var rectIndex: index
Repeater {
id: repeater2
model: modelData.count
Loader {
sourceComponent: Component {
id: comp
RectangleBoxBody {
width: 30
height: 30
bodyType: Body.Dynamic
MouseArea {
anchors.fill: parent
onClicked: { sourceComponent = undefined }
}
density: 1.5
friction: 0.2
restitution: 0.3
}
}
onLoaded: {
item.parent = root;
item.x = jsonPyr[rectIndex].startx + 47 * index;
item.y = jsonPyr[rectIndex].starty;
item.color = rectRow.rectColor;
item.border.color = 'white';
item.world = physicsWorld;
}
}
}
}
}
}
Component.onCompleted: {
var character = boxChar.createObject(root);
character.x = 306;
character.y = 180;
}
RectangleBoxBody {
id: ground
world: physicsWorld
height: 40
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
friction: 1
density: 1
color: "grey"
}
} main.cpp code: #include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <box2dplugin.h>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
Box2DPlugin plugin;
plugin.registerTypes("Box2DStatic");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
} The qtcreator output was:
|
Hi Bjorn, qmlProtectModule("Box2D", 2); should allow the static lib to be registered with: plugin.registerTypes("Box2D"); without problem from the existing dynamic lib ? |
@ThomasVogelpohl Yes, protecting the module prevents Qt from even searching for the plugin, so it will not get to the point of loading it and trying to make it register its types. See qmlProtectModule. |
Neat, that would make things a lot easier with the static lib. Thanks for the hint. |
Guys, I have adapted the code once again, this time the main.qml import are: import QtQuick 2.9
//import Box2DStatic 2.0
import Box2D 2.0
import "./shared" and the main.cpp code is: #include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <box2dplugin.h>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
/*
Box2DPlugin plugin;
plugin.registerTypes("Box2DStatic");
*/
Box2DPlugin plugin;
plugin.registerTypes("Box2D");
qmlProtectModule("Box2D", 2);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
} This time the project builds and run, except by the fact that there's no output, none window was showed. What should I be doing wrong? |
@ThomasVogelpohl will you update your repository with the new hint of @bjorn? |
@GugaDozero yes, I will change it. Just need to find time. This change makes my repo so similar to the stock qml-box2d, that it should be enabled in the stock repo anyway. |
I'm building a project that uses statically qmlbox2d.
I have copied the entire folder of qml-box2d into my project, added in the .pro file this:
and then in the main.cpp:
It builds ok, but when running i get this error in the title and the qml file is not loaded.
The imports of my main.qml are:
The text was updated successfully, but these errors were encountered: