Qt Creator/Designer and QML issue



  • Hello...

    I've just started with QML/QtQuick and have come up with an issue when editing with the designer in Qt Creator.

    When I try to work on my QML in designer, I get this when I bring it up:

    !http://feigenson.net/ForumUploads/ScreenShot2014-02-16at4.20.06PM.jpg(Qt Designer error)!

    The error is here on line 3:

    @import QtQuick 2.1
    import QtQuick.Controls 1.0
    import com.erflink.WeightPlates 1.0 as WeightPlate@

    The project builds and runs fine, since I register the C++ class with QML:
    @qmlRegisterSingletonType<MainWindow>("com.erflink.WeightPlates", 1, 0, "WeightPlateAPI", QML_MainWindow);@
    but the designer doesn't see it, presumably because the <code>qmlRegisterSingltetonType</code> happens only at run-time.

    So right now, I have to comment out that <code>import</code> line in order to edit my QML in designer.

    Is that the only way to do it?

    Thanks!

    -Eric



  • You could either create a QML plugin for "com.erflink.WeightPlates"
    and use QML_IMPORT_PATH/importPaths to point to it, or you could just create an empty fake plugin for "com.erflink.WeightPlates".

    If you use the fake plugin approach anything defined in "com.erflink.WeightPlates" will not work in the designer, but you will not get any error messages.



  • Thanks for your reply!

    Excuse my lack of knowledge in this area, but, to create a QML plugin, is that referred to as a "Qt Quick 2 Extension Plugin" in the "New project templates" dialog? Or is it a "Qt Creator Plugin?"

    I tried with the Qt Quick Extension template, put the plugin in the Qt Creator's plugin directory, and it didn't seem to get noticed. Of course, I'm not quite sure what I'm doing with the setup for the plugin in the first place.

    Would you please help me fill in some of the blanks? I'd appreciate it.

    Thanks!

    -Eric



  • Hi,

    Yes I was talking about a “Qt Quick 2 Extension Plugin” .
    For the Qt Quick plugin to be found, you need to add the path to QML_IMPORT_PATH in the .pro file.
    You might also need a .qmltypes file which contains the meta informatino for the code model.

    If the types defined in C++ are not directly relevant for designing, you can also just create a dummy plugin, but you still need to add the path to QML_IMPORT_PATH.



  • I am having the same problem using Qt Creator 3.1.0 and Qt 5.3.0 RC snapshot. I do not have any plugin dlls, my qmlRegisterSingletonType is in the main.cpp of my project. How to I tell the Qt Creator designer that this type exists?



  • My guess is that qmlRegisterSingletonType is not properly supported by the code model of Qt Creator.

    Any use of your singleton should be marked as an error by the code editor in this case. If this is the case can you create a mini example and file a bug report?



  • Only the import statement is marked as an error ("QML module not found"), the calls to the Singleton method(s) are not marked as an error. I suspect that I only have to put a qmldir file somewhere, but I did not find any documentation about the contents and the location of the file for this use case.



  • In the .pro file you can use QML_IMPORT_PATH to extend the search path for qml plugins.
    In this directory you can then put "fake" plugins in e.g. com/erflink/WeightPlates.

    the qmldir file would look like this:
    module com.erflink.WeightPlates

    For details you can look here: http://qt-project.org/doc/qt-5/qtqml-modules-qmldir.html



  • Thank you, the "module" line did it. I think that use case should really be documented.



  • same issue, I need create a fake extension project.
    But the problem is I have more than ten types to be registered. I need create them all.
    I think it really can be a bug in QT Creator.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.