2

I am very new to QT. I am following an example to load a .FBX file into a dialog.

ToolButton is clicked to load a .FBX file into the Scene3D:

main.qml

import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Scene3D 2.0
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0

ApplicationWindow
{
    visible: true
    width: 640
    height: 480
    title: qsTr("3D Viewer")

    header: ToolBar
    {
        ToolButton
        {
            text: "Open 3D Model"
            onPressed:
            {
                fileDialog.open()
            }
        }
    }

    FileDialog
    {
        id: fileDialog
        onAccepted:
        {
            sceneLoader.source = fileDialog.fileUrl
        }
    }

    Scene3D
    {
        anchors.fill: parent

        aspects: ["input", "logic"]
        cameraAspectRatioMode: Scene3D.AutomaticAspectRatio

        Entity
        {
            id: sceneRoot

            Camera
            {
                id: camera
                projectionType: CameraLens.PerspectiveProjection
                fieldOfView: 30
                aspectRatio: 16/9
                nearPlane : 0.1
                farPlane : 1000.0
                position: Qt.vector3d( 10.0, 0.0, 0.0 )
                upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
                viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
            }

            OrbitCameraController
            {
                camera: camera
            }

            components: [
                RenderSettings
                {
                    activeFrameGraph: ForwardRenderer
                    {
                        clearColor: Qt.rgba(0, 0.5, 1, 1)
                        camera: camera
                    }
                },
                InputSettings
                {
                }
            ]

            Entity
            {
                id: monkeyEntity
                components: [
                    SceneLoader
                    {
                        id: sceneLoader
                    }
                ]
            }
        }
    }
}

However, the dialog box does not even open and terminates with this error:

terminate called after throwing an instance of 'std::bad_alloc'

Not quite sure where did it come from since I cannot debug into a .qml file.

John Tan
  • 1,331
  • 1
  • 19
  • 35
  • What version of the imports are you using? I tried your example with the latest QML library and had to change `header` to `toolBar` because it wouldn't recognize `header` as a property on `ApplicationWindow`. Same for `onPressed` of the `ToolButton` - this had to be changed to `onClicked`. Other than that, the example works for me and I can view 3D objects. Although you probably should add a material to the entity you want to view to see it properly. – Florian Blume Oct 08 '18 at 07:35
  • @FlorianBlume I have included the imports in my edited question. I'm currently using Qt 5.11.2 MinGW 32 bit if that helps. In addition to the bad_alloc error, I do get the application exited with code 3 as well, supposely indicating some file not found error. Not quite sure what went wrong as I cloned the entire project from the example. If you don't mind, could you share your project with me? – John Tan Oct 08 '18 at 07:59
  • 1
    This is my [`main.qml`](https://pastebin.com/mwcQrwMc) and this my [`main.cpp`](https://pastebin.com/798uvVeP) - I did not add the surface format setting it was already there in a Qt examle and I left it. You only need to add the `main.qml` to a resoures file that doesn't have a prefix (or adjust the code in `main.cpp` to your liking). – Florian Blume Oct 08 '18 at 08:12
  • @FlorianBlume Thanks. Now at least the dialog is running without crashing. However, I get an error that states that `Found no suitable importer for plugin`. My best guess is that it is unable to locate the assimp used to load .FBX. Do you have to manually include the linkage to assimp inside the .pro file? if so, how do you go about doing that? – John Tan Oct 08 '18 at 08:24
  • Taking from your comment that you use MinGW for compilation, I assume that you are on Windows? Maybe this is the issue why it can't find the plugin, yes. I'm using Ubuntu and don't have to import anything. I'm not sure how to check if Assimp is installed on Windows, though. Looks like you have to compile it yourself... – Florian Blume Oct 08 '18 at 08:44
  • @FlorianBlume Thanks. Yes that is correct. From https://stackoverflow.com/questions/52697782/importing-objects-in-qt3d-doesnt-work-but-theres-not-error-message, I am suspecting that it might be my version of qt, as I am using the latest version, but I am not very sure. – John Tan Oct 08 '18 at 09:40
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181470/discussion-between-florian-blume-and-john-tan). – Florian Blume Oct 08 '18 at 10:28
  • Were you able to find a solution? – VP. Apr 10 '19 at 19:37

0 Answers0