Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Harmattan Qt + QML application that auto rotates
Forum Updated to NodeBB v4.3 + New Features

Harmattan Qt + QML application that auto rotates

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 4.3k 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.
  • I Offline
    I Offline
    Iktwo
    wrote on last edited by
    #1

    Hi, I'm trying to develop for Harmattan, I don't know if I'm doing things the right way in order to interact between Qt and QML, the program works but I've lost the ability to auto rotate, maybe there's another way to interact between those two.

    The basic is that instead of launching the default viewer:
    @QScopedPointer<QApplication> app(createApplication(argc, argv));
    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer->setMainQmlFile&#40;QLatin1String("qml/test/main.qml"&#41;);
    viewer->showExpanded();
    
    return app->exec&#40;&#41;;@
    

    I create a class tha inherits from QDeclarativeView and there I set the source QML file:

    @setSource(QUrl("/opt/test/qml/test/main.qml"));@

    Every time I need to access information from Qt I expose it using setContextProperty:

    @m_context = rootContext();
    m_context->setContextProperty("WMain", this);
    ...
    m_context->setContextProperty("test", QString("test");
    @

    by doing @m_context->setContextProperty("WMain", this);@ I can access slots in my C++ code..

    now in the main.cpp I do this

    @QApplication app(argc, argv);
    WMain wMain;
    wMain.show();
    return app.exec();@

    But I doesn't really rotate the aplication, I'm missing something or I'm doing something wrong, hope you can help, thanks!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      Did you implement function similar to

      @
      viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
      @

      I think this function tells Screen item what the orientation is and than Window/PageStackWindow uses Screen to rotate.

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • I Offline
        I Offline
        Iktwo
        wrote on last edited by
        #3

        Do I have to implement the function? cause It says that there's no matching function called setOrientation, so could you tell me how to implement it? thanks!

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on last edited by
          #4

          This function is generated when you create a Qt Quick project. You can find it in QmlApplicationViewer implementation.

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • I Offline
            I Offline
            Iktwo
            wrote on last edited by
            #5

            I tried using the function as it is generated, it doesn't work, do you have a working example of an application capable of rotating and communicating with c++? I don't know what I'm doing wrong, the contents rotates but the top and bottom bar doesn't

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              Hi Iktwo,

              Have a look at "qt-complex":http://developer.qt.nokia.com/wiki/category:Tools::QtComplex for a working example.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Iktwo
                wrote on last edited by
                #7

                Thanks Eddy QtComplex looks pretty, but I'm looking for a simple example about QML+C++ (I do know how to communicate with setContextProperty, but my application fails to rotate correctly)

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  Iktwo
                  wrote on last edited by
                  #8

                  This is what I'm getting, hope someone can help! Thanks!

                  !http://iktwo.wikidot.com/local--files/start/er1.png(Test 1)!

                  !http://iktwo.wikidot.com/local--files/start/er2.png(Test 2)!

                  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