Results 1 to 3 of 3

Thread: [solved] Register new type in qml file from C++...

  1. #1
    Join Date
    Mar 2015
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default [solved] Register new type in qml file from C++...

    Hello,

    I wrote an item: LineEdit.qml, and I have another qml 'main.qml) which creates many LineEdit items.
    It works fine if I put LineEdit.qml into a directory with qmldir file etc..
    But, that causes the need to carry several files, and this is not really friendly user. I would like to make all in one file.
    main.qml is loaded into C++/Qt application.

    So, I'm looking for solution about providing the LineEdit.qml from c++ into the qml context/engine/view.
    So the first try is to save the LineEdit.qml into my application resource file, and load it into QQmlComponent, but I got the error: LineEdit is not a type.

    Is there a way to do so ? I know that it possible to define my LineEdit through c++ class (subclassing QQuickItem or QQuickPaintedItem...) but it is easier for me if I keep the LineEdit.qml file approach as I don't have to get bored with painting code...


    Thanks
    Last edited by obiwankennedy; 5th February 2016 at 17:35.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Register new type in qml file from C++...

    Just put it into the resource and "import" that resource path.
    If you have main.qml in the resource as well, just use the relative path.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2015
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Register new type in qml file from C++...

    Yes, thanks, Actually I found this solution just after asking here.

Similar Threads

  1. Replies: 1
    Last Post: 28th June 2013, 02:44
  2. Replies: 3
    Last Post: 25th April 2013, 15:12
  3. How to get file type Icon ?
    By wirasto in forum Qt Programming
    Replies: 4
    Last Post: 12th July 2010, 13:18
  4. How to know file type
    By nrabara in forum Newbie
    Replies: 2
    Last Post: 16th December 2009, 14:30
  5. Replies: 2
    Last Post: 5th June 2008, 13:42

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.