Qml is not a type error

6 votes and 8 comments so far on Reddit

I have a large project (A) which is impractical to share. I am not getting an «XXX is not a type» and I do not understand why. I am using qmake and Qt Creator. Assuming they exist, what are ways to view detailed logs or other things to help me understand how components are being found? I would like to understand why this project is working.

The reason why this is important to me is related to the branch on the sample repo https://github.com/jh3010-qt-questions/qml_location/tree/not_working, which is not working, but appears to match what the referenced project above is doing (or not doing).

On the *_solution branches in the repo, I have implemented various solutions which all resolve the problem.

However, as best as I can determine, none of implemented solutions are what (A) is doing. Loader is not be used. .createObject is not used. There do not appear to be any imports. A qmldir is not being used. And, yet, (A) works.

What are other solutions for qml_location that have not been used?

It is possible I am glazing over what (A) is doing and will keep staring at it.

On the not_working branch, I get a «MyDeepComponent is not a type» error.

main.qml

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12

Window 
{
  width:   640
  height:  480
  visible: true

  title: qsTr( "Hello World" )

  Column
  {
    MyDeepComponent
    {
    }
  }
}

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

  QGuiApplication app(argc, argv);

  QQmlApplicationEngine engine;

  engine.addImportPath( "qrc:/qml" );

  const QUrl url(QStringLiteral("qrc:/main.qml"));

  QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                   &app, [url](QObject *obj, const QUrl &objUrl) {
    if (!obj && url == objUrl)
      QCoreApplication::exit(-1);
  }, Qt::QueuedConnection);
  engine.load(url);

  return app.exec();
}

qml.qrc

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
        <file>qml/MyDeepComponent.qml</file>
        <file>qml/MyDeepComponentForm.ui.qml</file>
        <file>qml/more/MyDeeperComponent.qml</file>
        <file>qml/more/MyDeeperComponentForm.ui.qml</file>
    </qresource>
</RCC>

qml_location.pro

QT += quick

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += 
        main.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

MyDeepComponentForm.ui.qml

import QtQuick 2.4

Rectangle {
  width: 40
  height: 40

  color: "red"
}

MyDeepComponent.qml

import QtQuick 2.4

MyDeepComponentForm {
}

The directory structure is:

$ tree qml_location
qml_location/
├── main.cpp
├── main.qml
├── qml
│   ├── MyDeepComponent.qml
│   ├── MyDeepComponentForm.ui.qml
│   └── more
│       ├── MyDeeperComponent.qml
│       └── MyDeeperComponentForm.ui.qml
├── qml.qrc
├── qml_location.pro
└── qml_location.pro.user


Todd

Hi all, new to using Qt creator/V-play so bare with me please….

So I am trying to make a unlimited running platformer, like flappy bird. I am actually using a V-play template to make this game.

I am trying to add bombs into the space that continue to randomly run onto the screen and you must avoid them with your plane.

I keep getting a type error message when i attempt to put the bomb into the scene, here is the code
(Level.qml)
import Felgo 3.0
import QtQuick 2.0
import “../entities”
import “../common”

Item {
id: level

Background {
anchors.horizontalCenter: parent.horizontalCenter
y: scene.gameWindowAnchorItem.y+scene.gameWindowAnchorItem.height-height
}

BorderElement {
x: scene.gameWindowAnchorItem.x
y: scene.gameWindowAnchorItem.y-20
width: scene.gameWindowAnchorItem.width
height: 20
}

BorderElement {
y: ground.y
x: scene.gameWindowAnchorItem.x
width: scene.gameWindowAnchorItem.width
height: 20
}

Bombs {
id: bombs1
delay: 0
}

Bombs {
id: bombs2
delay: 1.5
}

Ground {
id: ground
anchors.horizontalCenter: parent.horizontalCenter
y: scene.gameWindowAnchorItem.y+scene.gameWindowAnchorItem.height-height
}

function reset() {
bombs1.reset()
bombs2.reset()
ground.reset()
}

function stop() {
bombs1.stop()
bombs2.stop()
ground.stop()
}

function start() {
bombs1.start()
bombs2.start()
}
}
(bomb.qml)
import Felgo 3.0
import QtQuick 2.0

EntityBase {
id: bombElement
width: 40
height: 40
property int variationDistance: 70
property double delay: 0

MultiResolutionImage {
id: bomb
source: “../../assets/img/bomb.png”

}

BoxCollider {
id: collider
width: bomb.width
height: bomb.height
anchors.centerIn: bomb
bodyType: Body.Static
collisionTestingOnlyMode: true
fixture.onBeginContact: {
player.gameOver()
}
}

MovementAnimation {
id: animation
target: parent
property: “x”
velocity: -150
running: true
minPropertyValue: scene.gameWindowAnchorItem.x-bombElement.width*1.5
onLimitReached: {
reset()
}
}

function generateRandomValueBetween(minimum, maximum) {
return Math.random()*(maximum-minimum) + minimum
}

function reset() {
bombElement.x = scene.gameWindowAnchorItem.width+bombElement.width/2
bombElement.y = generateRandomValueBetween(-variationDistance, variationDistance)-scene.height/3
}

function start() {
delayTimer.restart()
}

function stop() {
animation.stop()
delayTimer.stop()
}

Timer {
id: delayTimer
interval: delay*1000
repeat: false
onTriggered: {
animation.start()
}
}

Component.onCompleted: {
reset()
}
}

These are the error messages.
file:///C:/Users/todd/OneDrive/Company/build-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-Debug/qml/MainItem.qml:46:5: Type GameScene unavailable
file:///C:/Users/todd/OneDrive/Company/build-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-Debug/qml/scenes/GameScene.qml:37:5: Type Level unavailable
file:///C:/Users/todd/OneDrive/Company/build-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-Debug/qml/game/Level.qml:28:5: Bombs is not a type
C:UserstoddOneDriveCompanybuild-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-DebugdebugGoPlane.exe exited with code 0


Alex

Felgo Team

Hi,

your bomb qml file is named Bomb.qml (or is it bomb.qml with lowercase, doesn’t really matter), WITHOUT an s. The name of the qml file equals the classname of that component when used. so in your code it must be

Bomb {
  // ...
}

and not

Bombs {
  // ...
}

That’s why it says Bombs is not a type, because the type you defined is Bomb instead.

Cheers,
Alex


Todd

Hey Alex, thanks for the quick response.

So I went in an updated accordingly, and I still get the same error message.

it is bomb.qml with a lowercase by the way.


Günther

Felgo Team

Hi Todd!

It’s best practice that types in QML start with an uppercase-letter, so I’d recommend using Bomb.qml as the name and use Bomb as type name in your QML code. The type name always matches the filename. One thing that might also be relevant, is that you import the folder where the QML file is placed so you can access the types.

Can you try again uppercase letter?

Best,
Günther


Todd

Hey Gunther,

I went in and updated the QML file with an uppercase B, its now Bomb.qml.

Im getting these errors

file:///C:/Users/todd/OneDrive/Company/build-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-Debug/qml/MainItem.qml:46:5: Type GameScene unavailable

file:///C:/Users/todd/OneDrive/Company/build-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-Debug/qml/scenes/GameScene.qml:37:5: Type Level unavailable

file:///C:/Users/todd/OneDrive/Company/build-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-Debug/qml/game/Level.qml:28:5: Type Bomb unavailable

file:///C:/Users/todd/OneDrive/Company/build-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-Debug/qml/entities/Bomb.qml: File name case mismatch

C:UserstoddOneDriveCompanybuild-GoPlane-Desktop_Qt_5_7_0_MinGW_32bit-DebugdebugGoPlane.exe exited with code 0


Günther

Felgo Team

Hi Todd,
it should be okay if both the file and the typename you use starts with an uppercase.
Please try to solve the error by making sure you get a fresh and clean build:
– Delete the build directory
– Open your project in Qt Creator
– Right-click the project in the Project Explorer and select “Clean”
– Right-click again and select “Run qmake”
– Build the project

Does it work now?


Todd

This might sound like a dumb question but when you say delete the build directory do you mean go into the actual file explorer and delete the project or is that something you do directly in qt creator?


Günther

Felgo Team

The build directory is created additionally to the project directory, usually as a neighbour directory of the project.
In the Qt Creator “Projects” tab, you can view or change the build directory for each build kit. The build directory also contains files from previous builds, because this allows to speed up the build process as e.g. only new or changed files will be rebuilt. You can safely delete this build folder from your file system, as it will be created again with the next build.

One other thing that might be relevant, is that for type or auto-completion issues, it can help to restart Qt Creator and reopen the project e.g. when you change a type-name, as Qt Creator then reloads all types and autocompletion data.

Best,
Günther


Todd

Hey again Gunther…

So I went in and deleted the files and re built/cleaned them.

I still continue to get these errors:

qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method

qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto

qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb

qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_negotiated

qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated

file:///C:/Users/todd/OneDrive/Company/qml/MainItem.qml:46:3: Type GameScene unavailable

file:///C:/Users/todd/OneDrive/Company/qml/scenes/GameScene.qml:37:3: Type Level unavailable

file:///C:/Users/todd/OneDrive/Company/qml/game/Level.qml:28:3: Bombs is not a type

C:UserstoddOneDriveCompanyreleaseFlappyBird.exe exited with code 0

Is it something with my code?


Todd

And by the way I was working on this on both my desktop and laptop via onedrive, I dont see why it would be a problem but just thought I’d mention it.


Alex

Felgo Team

file:///C:/Users/todd/OneDrive/Company/qml/game/Level.qml:28:3: Bombs is not a type

Again you are obviously using “Bombs” in your code while your qml files are named “Bomb


Todd

Alex,

I set it back to bomb but now I get these

qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method

qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto

qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb

qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_negotiated

file:///C:/Users/todd/OneDrive/Company/qml/MainItem.qml:46:3: Type GameScene unavailable

file:///C:/Users/todd/OneDrive/Company/qml/scenes/GameScene.qml:37:3: Type Level unavailable

file:///C:/Users/todd/OneDrive/Company/qml/game/Level.qml:28:3: Type Bomb unavailable

file:///C:/Users/todd/OneDrive/Company/qml/entities/Bomb.qml:16:7: id is not unique

qt.network.ssl: QSslSocket: cannot call unresolved function SSL_get0_next_proto_negotiated

C:UserstoddOneDriveCompanyreleaseFlappyBird.exe exited with code 0

The reason i set it to bombs is because of the flappy bird template has the same thing set as “pipes”


Günther

Felgo Team

Hi Todd!

In the flappy bird game, the QML file is also named Pipes.qml (not Pipe.qml), which is why the name in QML is then Pipes.

The new error

file:///C:/Users/todd/OneDrive/Company/qml/entities/Bomb.qml:16:7: id is not unique
suggests that at there are two items within Bomb.qml that use the same id, which is not allowed. Please choose another id for one of them, for example the id specified at line 16 in Bomb.qml.

You can also have a look at our Getting Started with QML tutorial to learn more about the basic concepts.

Best,
Günther


Todd

Thank you… yeah I’ve been looking through tutorials and such so I am learning.

Now the game runs but the bombs don’t show up for me. 🙁

Ill check out your link later today


Todd

Update,

I got it working Gunther, thank you for everything

  • Home
  • Forum
  • Qt
  • Qt Quick
  • ToolTip is not a type

  1. 13th March 2015, 07:51


    #1

    Default ToolTip is not a type

    I am trying to add tool tip to my items added in my qml page.

    The ToolTip code I took from interner.

    1. //ToolTip.qml

    2. import QtQuick 2.0

    3. import QtQuick.Controls 1.1

    4. import QtGraphicalEffects 1.0

    5. Item {

    6. id: toolTipRoot

    7. width: toolTip.contentWidth

    8. height: toolTipContainer.height

    9. visible: false

    10. clip: false

    11. z: 999999999

    12. property alias text: toolTip.text

    13. property alias radius: content.radius

    14. property alias backgroundColor: content.color

    15. property alias textColor: toolTip.color

    16. property alias font: toolTip.font

    17. property var target: null

    18. function onMouseHover(x, y)

    19. {

    20. var obj = toolTipRoot.target.mapToItem(toolTipRoot.parent, x, y);

    21. toolTipRoot.x = obj.x;

    22. toolTipRoot.y = obj.y + 5;

    23. }

    24. function onVisibleStatus(flag)

    25. {

    26. toolTipRoot.visible = flag;

    27. }

    28. Component.onCompleted: {

    29. var itemParent = toolTipRoot.target;

    30. var newObject = Qt.createQmlObject('import QtQuick 2.0; MouseArea {signal mouserHover(int x, int y); signal showChanged(bool flag); anchors.fill:parent; hoverEnabled: true; onPositionChanged: {mouserHover(mouseX, mouseY)} onEntered: {showChanged(true)} onExited:{showChanged(false)} onClicked:{parent.focus = true}}',

    31. itemParent, "mouseItem");

    32. newObject.mouserHover.connect(onMouseHover);

    33. newObject.showChanged.connect(onVisibleStatus);

    34. }

    35. Item {

    36. id: toolTipContainer

    37. z: toolTipRoot.z + 1

    38. width: content.width + (2*toolTipShadow.radius)

    39. height: content.height + (2*toolTipShadow.radius)

    40. Rectangle {

    41. id: content

    42. anchors.centerIn: parent

    43. width: toolTipRoot.width

    44. height: toolTip.contentHeight + 10

    45. radius: 3

    46. Text {

    47. id: toolTip

    48. anchors {fill: parent; margins: 5}

    49. wrapMode: Text.WrapAnywhere

    50. }

    51. }

    52. }

    53. DropShadow {

    54. id: toolTipShadow

    55. z: toolTipRoot.z + 1

    56. anchors.fill: source

    57. cached: true

    58. horizontalOffset: 4

    59. verticalOffset: 4

    60. radius: 8.0

    61. samples: 16

    62. color: "#80000000"

    63. smooth: true

    64. source: toolTipContainer

    65. }

    66. Behavior on visible { NumberAnimation { duration: 200 }}

    67. }

    To copy to clipboard, switch view to plain text mode 

    http://qt-project.org/wiki/QtQuick_ToolTip_Component

    I am trying to add as below. Let me know if I am doing it correct. If not please guide in using it correct to display the tool tip properly.

    1. //BrowserWindow.qml

    2. Rectangle {

    3. width: 200

    4. height:26

    5. anchors.right: parent.right

    6. anchors.rightMargin: 30

    7. anchors.verticalCenter: parent.verticalCenter

    8. color: "#FFFFFF"

    9. border.color: "#e1dedb"

    10. border.width: 3

    11. radius: 10

    12. id : searchBox

    13. Image {

    14. id: search

    15. width: 18

    16. height: 18

    17. anchors.centerIn: parent

    18. source: "images/search.png"

    19. }

    20. ToolTip {

    21. id: searchToolTip

    22. width: 200

    23. target: searchBox

    24. text: "Search"

    25. }

    26. }

    To copy to clipboard, switch view to plain text mode 

    The page is not loaded and error is
    qrc:/Main.qml:167:5: ToolTip is not a type


  2. 13th March 2015, 08:26


    #2

    Default Re: ToolTip is not a type

    Is ToolTip.qml part of the resource?

    Cheers,
    _


  3. 14th March 2015, 05:40


    #3

    Default Re: ToolTip is not a type

    I have had added it.
    Now I am getting errors as below
    qrc:/Main.qml:43:13: Type ToolTip unavailable
    qrc:/ToolTip.qml:2:1: module «QtQuick.Controls» is not installed
    qrc:/ToolTip.qml:3:1:module «QtGraphicalEffects» module


  4. 14th March 2015, 10:14


    #4

    Default Re: ToolTip is not a type

    Do you have those modules in your installation?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. 14th March 2015, 11:13


    #5

    Default Re: ToolTip is not a type

    I find those folder my QT directory

    DTPC-184N:~ user$ ls /Applications/QT/5.4/clang_64/qml/QtGraphicalEffects
    Blend.qml FastBlur.qml OpacityMask.qml
    BrightnessContrast.qml GammaAdjust.qml RadialBlur.qml
    ColorOverlay.qml GaussianBlur.qml RadialGradient.qml
    Colorize.qml Glow.qml RectangularGlow.qml
    ConicalGradient.qml HueSaturation.qml RecursiveBlur.qml
    Desaturate.qml InnerShadow.qml ThresholdMask.qml
    DirectionalBlur.qml LevelAdjust.qml ZoomBlur.qml
    Displace.qml LinearGradient.qml private
    DropShadow.qml MaskedBlur.qml qmldir
    DTPC-184N:~ user$ ls /Applications/QT/5.4/clang_64/qml/QtQuick/Controls
    ApplicationWindow.qml StatusBar.qml
    BusyIndicator.qml Styles
    Button.qml Switch.qml
    Calendar.qml Tab.qml
    CheckBox.qml TabView.qml
    ComboBox.qml TableView.qml
    GroupBox.qml TableViewColumn.qml
    Label.qml TextArea.qml
    Menu.qml TextField.qml
    MenuBar.qml ToolBar.qml
    Private ToolButton.qml
    ProgressBar.qml controls.pro
    RadioButton.qml libqtquickcontrolsplugin.dylib
    ScrollView.qml libqtquickcontrolsplugin_debug.dylib
    Slider.qml plugin.cpp
    SpinBox.qml plugin.h
    SplitView.qml plugins.qmltypes
    StackView.qml qmldir
    StackViewDelegate.qml qmldir 2
    StackViewTransition.qml qtquickcontrols-overview.qdoc


  6. 14th March 2015, 11:32


    #6

    Default Re: ToolTip is not a type

    Are you sure this is the installation of Qt you are using in your application?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. 14th March 2015, 12:09


    #7

    Default Re: ToolTip is not a type


  8. 14th March 2015, 13:05


    #8

    Default Re: ToolTip is not a type

    In that case run you app under strace and see if it tries to access files in those directories.

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. Default Re: ToolTip is not a type

    could be an import missing???


Similar Threads

  1. Tooltip

    By ich in forum Qt Programming

    Replies: 1

    Last Post: 19th November 2014, 18:52

  2. Replies: 2

    Last Post: 27th November 2013, 01:56

  3. Replies: 9

    Last Post: 5th November 2010, 21:31

  4. Replies: 2

    Last Post: 22nd December 2009, 21:52

  5. Replies: 27

    Last Post: 3rd August 2007, 11:42

Tags for this Thread

Bookmarks

Bookmarks


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Forum Rules

Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.

Понравилась статья? Поделить с друзьями:
  • Ql query error при обновлении битрикс
  • Qiwi платеж не проведен внутренняя ошибка
  • Qiwi ошибочный перевод как вернуть
  • Qiwi ошибка при пополнении
  • Python requests ошибка 403