Results 1 to 10 of 10

Thread: Problems with QtQuick wizard generated project

  1. #1
    Join Date
    Feb 2014
    Posts
    14
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Problems with QtQuick wizard generated project

    Hello,

    I'm trying to add a C++ defined type to a simple QML file, but when I start debugging the application I receive the following error: "module "APP_CHILD" is not installed
    import APP_CHILD 1.0".

    The application I'm running is derived from a wizard generated QtQuick application which is meant to handle native system events some way.

    The program is structured as follows:

    qtquick2applicationviewer/qtquick2applicationviewer.cpp (Wizard generated)
    qtquick2applicationviewer/qtquick2applicationviewer.h (Wizard generated)
    qtquick2applicationviewer/qtquick2applicationviewer.pri (Wizard generated)
    qml/provaintegrazione/main.qml
    app.cpp
    app.h
    main.cpp
    provaintegrazione.pro
    provaintegrazione.pro.user
    and this is the code of the files I modified by myself:

    app.h

    Qt Code:
    1. #ifndef APP_H
    2. #define APP_H
    3.  
    4. #include <QTimer>
    5. #include "qtquick2applicationviewer.h"
    6.  
    7. class cAppChild : public QObject
    8. {
    9. Q_OBJECT
    10.  
    11. QTimer timer;
    12. bool check;
    13.  
    14. public:
    15. cAppChild();
    16. virtual ~cAppChild(){}
    17.  
    18. private slots:
    19. void change(){ check = !check; timer.start(); }
    20. };
    21.  
    22. class cApp : public QtQuick2ApplicationViewer
    23. {
    24. Q_OBJECT
    25.  
    26. bool nativeEvent(const QByteArray &eventType, void *message, long *result);
    27.  
    28. public:
    29. explicit cApp(QWindow *parent = 0);
    30. virtual ~cApp();
    31. };
    32.  
    33. #endif // APP_H
    To copy to clipboard, switch view to plain text mode 


    app.cpp

    Qt Code:
    1. #include <QtDeclarative>
    2. #include "app.h"
    3.  
    4. cAppChild::cAppChild()
    5. {
    6. check = false;
    7. timer.start();
    8. //Connections for attach/detach notification
    9. connect(&timer, SIGNAL(timeout()), this, SLOT(change()));
    10. }
    11.  
    12.  
    13.  
    14. cApp::cApp(QWindow *parent) : QtQuick2ApplicationViewer(parent)
    15. {
    16. }
    17.  
    18. cApp::~cApp()
    19. {
    20. }
    21.  
    22. bool cApp::nativeEvent(const QByteArray &eventType, void *message, long *result)
    23. {
    24. if( eventType == "windows_generic_MSG" )
    25. {
    26. // Some kind of event handling.
    27. }
    28. return false;
    29. }
    To copy to clipboard, switch view to plain text mode 


    main.cpp

    Qt Code:
    1. #include <QtGui/QGuiApplication>
    2. #include <QtDeclarative>
    3. #include "app.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QGuiApplication app(argc, argv);
    8.  
    9. qmlRegisterType<cAppChild>("APP_CHILD", 1, 0, "appchild");
    10.  
    11. cAppChild myApp;
    12.  
    13. cApp viewer;
    14. viewer.setMainQmlFile(QStringLiteral("qml/provaintegrazione/main.qml"));
    15. viewer.showExpanded();
    16.  
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    qml/provaintegrazione/main.qml

    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.0
    3. import APP_CHILD 1.0
    4.  
    5. ApplicationWindow
    6. {
    7. id: main_window
    8. Rectangle
    9. {
    10. id: pippo
    11. width: 360
    12. height: 360
    13. color: "red"
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 


    Can anybody try to use the code above on his QtCreator and explain me how to make the qml code recognize the APP_CHILD module?
    Last edited by anda_skoa; 16th March 2014 at 12:56. Reason: changed [qtclass] to [code]

  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: Problems with QtQuick wizard generated project

    That looks OK. Are you sure you are running the actual application, not just "running" the QML file?

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    14
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with QtQuick wizard generated project

    I didn't understand your question. The QML file should act as UI and use my C++ class registered as a new QML type. Now the main.cpp file was created by the QtCreator wizard, I just added the type registration for QML and used a class inherited by the class within qtquick2applicationviewer.h in order to use my own nativeEvent() function in the future. What I don't understand is why the import statement inside main.qml file is not recognized. Could you please try to create a QtQuick project like this, add my files and see if everything works on your side? Maybe an experienced Qt programmer like you could understand the problem better than I can do.

  4. #4
    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: Problems with QtQuick wizard generated project

    Quote Originally Posted by enrico5th View Post
    I didn't understand your question.
    you wrote "when I start debugging" and I was asking what exactly you were doing.
    Did you run the application or just "run" the QML file.

    Quote Originally Posted by enrico5th View Post
    What I don't understand is why the import statement inside main.qml file is not recognized.
    It should, hence my question to narrow down possible errors.

    Quote Originally Posted by enrico5th View Post
    Could you please try to create a QtQuick project like this, add my files and see if everything works on your side? Maybe an experienced Qt programmer like you could understand the problem better than I can do.
    I can do that if you attach a buildable example.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2014
    Posts
    14
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with QtQuick wizard generated project

    I run the whole application.
    You can find the whole project attached to this post.
    Attached Files Attached Files

  6. #6
    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: Problems with QtQuick wizard generated project

    After I got it to build, it worked for me.

    provaintegrazione.zip

    Cheers,
    _

  7. #7
    Join Date
    Feb 2014
    Posts
    14
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with QtQuick wizard generated project

    Does it work without any modification? When I build and run it, a little white window appears on the screen (instead of a big red rectangle), then I look at the Application Output window and the message "module "APP_CHILD" is not installed import APP_CHILD 1.0" has been output there. I tried on two different platform and I got the same problem. I'm now asking to myself what's the difference between my platform and yours.

  8. #8
    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: Problems with QtQuick wizard generated project

    Lets try with a very simple example

    main.cpp
    Qt Code:
    1. #include <QtQml>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QCoreApplication app(argc, argv);
    6.  
    7. qmlRegisterType<QTimer>("APP_CHILD", 1, 0, "AppChild");
    8.  
    9. QQmlEngine engine;
    10.  
    11. QQmlComponent component(&engine);
    12. component.setData("import APP_CHILD 1.0\n\nAppChild { }", QUrl());
    13. qDebug() << "created object=" << component.create();
    14.  
    15. return 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

    appchildtest.pro
    Qt Code:
    1. TEMPLATE = app
    2. TARGET = appchildtest
    3. INCLUDEPATH += .
    4.  
    5. # Input
    6. SOURCES += main.cpp
    7.  
    8. QT += qml
    To copy to clipboard, switch view to plain text mode 

    Executing that should give you an output like this:

    created object= QTimer(0xc2b250)

    Once you've veryfied that, add you class and register it instead of QTimer.

    Cheers,
    _

  9. #9
    Join Date
    Feb 2014
    Posts
    14
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with QtQuick wizard generated project

    Your example works perfectly, this makes me think there's some problem in the way I've attached the main.qml file in my project. But that was done automatically by the Qt Quick wizard for projects creation. This thing is making me crazy!!!

  10. #10
    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: Problems with QtQuick wizard generated project

    Have you tried running the program from a terminal/shell?

    Just to make sure you are actually running the program, not just "running" the QML file.

    Cheers,
    _

Similar Threads

  1. How to create a QtQuick 1 Application project?
    By TheIndependentAquarius in forum Qt Tools
    Replies: 1
    Last Post: 23rd October 2013, 12:02
  2. MSVC Project generated using qmake - turn off flat structure
    By Piskvorkar in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2013, 00:25
  3. Replies: 1
    Last Post: 29th September 2011, 12:14
  4. visualize qtQuick project
    By amadanes in forum Newbie
    Replies: 1
    Last Post: 9th May 2011, 00:15
  5. Qt Creator Crossplatform project wizard
    By lunarcloud in forum Qt Tools
    Replies: 0
    Last Post: 11th April 2011, 08:43

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.