Unsolved MessageDialog issue
-
Hi everyone! I have a problem with launching my Windows Qt 5.7 MinGW-builded project in QtCreator.
There is an import looks like this:
import QtQuick 2.7 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Controls 2.0
And I have a MessageDialog in my main.qml to implement typical modal MessageBox. After successful project building, when I try to launch my program in QtCreator context, application log shows:
QQmlApplicationEngine failed to load component qrc:/main.qml:129 ??? ?MessageDialog? ?????????? qrc:/QtQuick/Dialogs/DefaultMessageDialog.qml:41 ?????? ?QtQuick.Controls? ?????? 1.2 ?? ??????????
Okay, let's check DefaultMessageDialog.qml out:
import QtQuick.Controls 1.2
I cannot remove
QtQuick.Controls 2.0
from my main.qml because of using Button object on the form.Honourable experts, what should I do with these two conflicting imports of different versions? Please, help.
-
@Tikani What are the question marks ?
Also can youimport QtQuick.Controls 2.0
beforeimport QtQuick.Dialogs 1.2
and see if the same error persists? -
Hi @Tikani,
There are Button in QtQuick.Controls 1.4... Maybe you can use this ?
If no, have you try this import
import QtQuick.Controls 1.4 as ControlA
?To finish, try with creating yourte dialog in other QML document, for example MyDialog.qml where you don't import QtQuick.Controls 2.0.
-
Hi! Don't invest too much work in a "nice" solution, we get new Quick Controls 2 dialogs with Qt 5.8, see: New Features in 5.8, Qt 5.8 Release.
-
@p3c0 I don't know what the question marks are since I simply copy-pasted here the contents of application log panel. I guess it is due to lack of debug information (however, it is strange, because I built the project with chosen "Debug" configuration in the bottom-left corner).
main.qml
import QtQuick 2.7 import QtQuick.Window 2.2 import QtQuick.Controls 2.0 import QtQuick.Dialogs 1.2 Window { visible: true width: 640 height: 480 maximumHeight: height maximumWidth: width minimumHeight: height minimumWidth: width color: "white" title: "Однослойный перцептрон" Component.onCompleted: { setX(Screen.width/2 - width/2) setY(Screen.height/2 - height/2) neuro.loadWeights() } property int xpos property int ypos property bool hold property bool clearCanvas:false Canvas { id:canvas anchors.top: parent.top width: 640 height: 410 onPaint: { var ctx = getContext('2d') if(clearCanvas) { ctx.fillStyle = "white" ctx.fillRect(0,0,width,height) clearCanvas=false } else { ctx.lineWidth = 30 ctx.strokeStyle = 'blue' ctx.beginPath() ctx.moveTo(xpos,ypos) xpos = area.mouseX ypos = area.mouseY ctx.lineTo(xpos, ypos) ctx.stroke() } } MouseArea { id:area anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton onPressed: { if(mouse.buttons & Qt.LeftButton) { hold=true xpos = mouseX ypos = mouseY } } onPositionChanged: { if(hold & (mouse.buttons & Qt.LeftButton)) { canvas.requestPaint() } } onReleased: { hold = false } } } Button { id:recognize anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter height: 50 width: 300 anchors.bottomMargin: 8 text:"Распознать" onClicked: { var image = canvas.getContext('2d').getImageData(0,0,canvas.width,canvas.height) var norm_px = [] for(var i = 0, n=image.data.length; i<n; i+=4) { if(image.data[i]===0 && image.data[i+1]===0 && image.data[i+2]===255 && image.data[i+3]===255) { norm_px.push(1) } else { norm_px.push(0) } } neuro.signal = norm_px neuro.calculate() if (neuro.exitSignal===1) { recognitionState.text="Этот символ - тэта" } else if (neuro.exitSignal===2) { recognitionState.text="Этот символ - пси" } else recognitionState.text="Символ не распознан." recognitionState.open() canvas.requestPaint() clearCanvas=true } } MessageDialog { id:recognitionState title:"Классификация" icon:StandardIcon.Information } }
Here I have changed the imports according to your advice but I get the same error.
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
I suspect that error occurs when
QQmlApplicationEngine
looks through main.qml resolving dependencies recursively of given objects and when it reaches MessageDialog then it gets 2 conflicting imports. I've tried to importQtQuick.Controls 1.2
in main.qml but it gives nothing. -
@CharlieG Unfortunately, namespace tricks didn't help :( I'll try the last variant you suggested.
-
@CharlieG Your last variant hasn't helped too. I will try to craft "homemade" MessageBox by combining Popup and Rectangle. Hope it can be a solution in my case.
-
@Tikani, I've tested your code and I don't have this problem on Mac OS X (build is correct). But I can't make a full test beacause it's missing
neuro
. -