I am facing a QQmlApplicationEngine failure while loading a component. The error is mentioned below:
QQmlApplicationEngine failed to load component
qrc:/KBButton.qml:54:5: SoundEffect is not a type
The following section of KBButton.qml is failing:
import QtQuick 2.0
import QtMultimedia 5.15
Rectangle {
id: kbButton
property double size: 100
x: centerX - width / 2
y: centerY - height / 2
SoundEffect { ~~~~~~~~~~~~~~~~~~~~~~Error occurs here. Unknown Component (M300)
id: clickSound
source: "resources/ClickSound.wav"
}
onClick: {
isSelected = false;
expManager.logKeyClicked(objectName)
clickSound.play();
}
}
.pro file contains the following. Although I am importing QtMultimedia in qml files and not in C files, I still added the multimedia and multimediawidgets to qmake project file
QT = qml quick widgets core quickcontrols2 multimedia multimediawidgets
The code model could be reset using the Main Menu option available in QtCreator, as suggested by some online forums:
Tools > QML/JS > Reset Code Model
but this did not work. It didn't help either to run qmake again.
What can be done to resolve this error?
CodePudding user response:
As far as I know, QML should load the right version for you, so in this case it seems a good solution is to remove the version from your import
: import QtMultimedia
instead of import QtMultimedia 5.15
More info about the import statement: https://doc.qt.io/qt-6/qtqml-syntax-imports.html