Results 1 to 12 of 12

Thread: Multi 'page' QML application issues with external QML/Javascript

Hybrid View

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

    Default Re: Multi 'page' QML application issues with external QML/Javascript

    Quote Originally Posted by scgrant327 View Post
    Property bindings look like they will work fine for my purpose.
    Excellent, bindings on C++ properties is definitely the way to go.
    Way more elegant than making C++ code dependent on QML code.

    Quote Originally Posted by scgrant327 View Post
    When calling my javascript functions, why can I not access my QML objects? I get errors about the object being undefined. I've tried by using the alias for the object, the id for the object and the QML file name that houses the object....all give the same error.
    Can you show such a function and where the objects are defined?

    For example your gpsOneShotUpdate() function should be fine if there is an object with id mainWin in the same file or a property with the name mainWin in the object the function is in.

    Quote Originally Posted by scgrant327 View Post
    AND... do I need to 'import' the parent and SubPages folders into each of my SubPages/*.qml files?
    import allows you access to types, just like includes in C++.
    The current directory, i.e. the directory the current QML file is in, is always implicitly imported.

    In your case you don't need to import SubPages in main.qml since you are using a Loader, you are not instantiating objects of these types directly in QML code.

    Quote Originally Posted by scgrant327 View Post
    I ask because if I try to reference an object in SubPages/Page1.qml from SubPages/Page2.qml, I get an error about that object being undefined.
    Access to objects has nothing to do with imports.

    Quote Originally Posted by scgrant327 View Post
    For instance, when I load SubPages/Page2.qml using the loader I showed earlier. Page2 has a Label that when clicked on will change a value on Page1. But, if I try this I get an error:

    In Page2:
    Qt Code:
    1. onClicked: {
    2. Page1.page1Label.text = page2Label.text
    3. Page1.page1Label.color = "lime"
    4. page2Label.color = "darkred"
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 
    Page1 is not a valid id nor a valid property name (both need to start with a lower case letter).

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    scgrant327 (24th February 2016)

  3. #2
    Join Date
    May 2011
    Posts
    81
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Multi 'page' QML application issues with external QML/Javascript

    Ok, I ended up declaring non-visible instances of the SubPages in my main.qml. Works pretty well with my custom 'loader' javascript function to show/hide each page on demand.

    Thanks for the help!

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

    Default Re: Multi 'page' QML application issues with external QML/Javascript

    You really like doing things imperatively :-)

    However, you might want to look into doing things declaratively for future projects, it really pays off and makes things easier.

    Cheers,
    _

Similar Threads

  1. Multi-page application with Qt Designer
    By chiruL in forum Newbie
    Replies: 1
    Last Post: 23rd January 2016, 11:08
  2. Webkit open new javascript Page
    By ShapeShiftme in forum Qt Programming
    Replies: 3
    Last Post: 25th October 2012, 09:46
  3. Multi-page application and QStackedWidget
    By Mek82 in forum Qt Programming
    Replies: 10
    Last Post: 31st October 2010, 23:06
  4. multi page Application
    By ilpaso in forum Qt Programming
    Replies: 2
    Last Post: 3rd September 2010, 10:36
  5. Replies: 3
    Last Post: 25th February 2010, 09:53

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.