Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PyQt5.5 vs QML vs C++ QML Plugin under Windows (7 or 10) path problems
Forum Updated to NodeBB v4.3 + New Features

PyQt5.5 vs QML vs C++ QML Plugin under Windows (7 or 10) path problems

Scheduled Pinned Locked Moved Unsolved Language Bindings
1 Posts 1 Posters 845 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AlicemirrorA Offline
    AlicemirrorA Offline
    Alicemirror
    wrote on last edited by
    #1

    Hi to all. I wrote Path problems in the topic title because I am 99% sure that it depends from something in the path settings. I have three objects:

    • QML main that PyQt5 will set and read a data type
    • Python test that just creates the type and manages it
    • C++ QML Plugin that do some graph calculations used by QML element
    • QML Graphic document that uses the C++ Qt Plugin

    With these elements the scenario is the following:

    Main-Folder => main.py
      |
     LiveData-Folder => main.qml and LiveData.qml
                |
               imports-Folder
                      |
                    LiveData-Folder => QML components
                                    => C++ QtPlugin dll
                                    => qmldir
    

    Considered separately, the main.py program correctly connects with main.qml and get the data types.
    When launched by QMLScene the LiveData.qml works fine.

    If I try to join the two parts and launch the main.py the python reports syntax errors related to the wrong import of components.

    Here there are the most meaningful parts of the sources trying to complete the description of the issue. Any help of suggestion is welcome :)

    main.py

    import sys
    
    from PyQt5.QtCore import pyqtProperty, QCoreApplication, QObject, QUrl
    from PyQt5.QtQml import qmlRegisterType, QQmlComponent, QQmlEngine
    
    # This is the type that will be registered with QML.  It must be a
    # sub-class of QObject.
    class LDSetType(QObject):
        def __init__(self, parent=None):
            super(LDSetType, self).__init__()
    
            # Initialise the value of the properties.
            self._name = ''
    
        # Define the getter of the property.
        @pyqtProperty('QString')
        def name(self):
            return self._name
    
        # Define the setter of the 'name' property.
        @name.setter
        def name(self, name):
            self._name = name
    
    # Create the application instance.
    app = QCoreApplication(sys.argv)
    
    # Register the Python type.  Its URI is 'PyQtLiveGraph', it's v1.0 and the type
    # will be called 'LDSet' in QML.
    qmlRegisterType(LDSetType, 'PyQtLiveGraph', 1, 0, 'LDSet')
    
    # Create a QML engine.
    engine = QQmlEngine()
    engine.addImportPath("imports") # last try for test with no results...
    
    # Create a component factory and load the QML script.
    component = QQmlComponent(engine)
    component.loadUrl(QUrl('LiveData/main.qml'))
    
    if component.status() == component.Error:
        print(component.errorString())
        print(component.errors())
    else:
        # Print the value of the properties.
        myComponent = component.create()
        print("The myComponent's name is %s." % myComponent.name)
    

    LiveData/main.qml

    import QtQuick 2.2
    import PyQtLiveGraph 1.0
    
    LDSet {
        name: "QML Type data"
    
    }
    
    Rectangle {
        visible: true
        width: 640
        height: 480
    
    }
    
    

    Just in this very simple case, also without using the C++QML Plugin the mentioned problem arises:

    When I launch the command >python main.py the console response is syntax error to the line of the Rectangle object definition. The only QML that works correctly is the the following main.qml:

    import QtQuick 2.2
    import PyQtLiveGraph 1.0
    
    LDSet {
        name: "QML Type data"
    
    }
    
    //Rectangle {
    //    visible: true
    //    width: 640
    //    height: 480
    
    //}
    
    

    Running the command >python main.py from the Python folder the result is the following (PyQtLiveGraph.py is the real name of main.py):

    **C:\Python27\python.exe "C:/Users/B.../PyQtLiveGraph/PyQtLiveGraph.py"

    The myComponent's name is QML Type data.**

    Enrico Miglino (aka Alicemirror)
    Balearic Dynamics
    Islas Baleares, Ibiza (Spain)
    www.balearicdynamics.com

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved