Results 1 to 11 of 11

Thread: How to write code in C language instead of QML?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write code in C language instead of QML?

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #include <QtGui/QApplication>
    4.  
    5. #include <QAccelerometer>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication app(argc, argv);
    10.  
    11. MainWindow mainWindow;
    12. mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
    13. mainWindow.showExpanded();
    14.  
    15. // On the heap (deleted when this object is deleted)
    16. QAccelerometer *sensor = new QAccelerometer(this);
    17.  
    18. // On the stack (deleted when the current scope ends)
    19. QOrientationSensor orient_sensor;
    20.  
    21. // start the sensor
    22. QSensor sensor("QAccelerometer");
    23. sensor.start();
    24.  
    25. // later
    26. QSensorReading *reading = sensor.reading();
    27. qreal x = reading->property("x").value<qreal>();
    28. qreal y = reading->value(1).value<qreal>();
    29.  
    30. QAccelerometer sensor;
    31. sensor.setProperty("maximumReadingCount", 100);
    32. sensor.setProperty("processAllReadings", true);
    33.  
    34.  
    35.  
    36. return app.exec();
    37. }
    To copy to clipboard, switch view to plain text mode 
    With using this code which I written basing on the codes from your site I still receive compilation errors. For example
    C:\...\main.cpp:5: error: QAccelerometer: No such file or directory
    Or
    C:\...\main.cpp:16: error: 'QAccelerometer' was not declared in this scope
    or
    C:\...\main.cpp:16: error: expected type-specifier before 'QAccelerometer'
    How to repair this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to write code in C language instead of QML?

    You probably didn't enable mobility/sensor support for your project. Or you simply don't have Qt Mobility installed.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write code in C language instead of QML?

    Is it enough to enable sensor support in my project if I select Qt Widget Project->Mobile Qt Application? What else do I have to do to enable sensor support?

    Is there anywhere easy instalation of Qt Mobility? When I select configure file in Qt Mobility open source *.rar file it shows cmd window for a moment and it doesn't install Qt Mobility. And "nmake" and "nmake install" commands don't work.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to write code in C language instead of QML?

    Quote Originally Posted by tom634 View Post
    Is it enough to enable sensor support in my project if I select Qt Widget Project->Mobile Qt Application?
    No.

    What else do I have to do to enable sensor support?
    You need to read QtMobility docs. I suspect giving you a direct answer would not help you with anything as you'd come back again in 10 minutes with a next problem related to not reading the manual prior to using some solution.

    Is there anywhere easy instalation of Qt Mobility? When I select configure file in Qt Mobility open source *.rar file it shows cmd window for a moment and it doesn't install Qt Mobility. And "nmake" and "nmake install" commands don't work.
    I've never heard of any rar file containing Qt Mobility so I can't help.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write code in C language instead of QML?

    Are you sure you are using the right package? As Qt Mobility is available as part of the Qt SDK.

Similar Threads

  1. Replies: 2
    Last Post: 2nd November 2010, 05:15
  2. Write Qt program to a language with special symbols
    By hakermania in forum Qt Programming
    Replies: 9
    Last Post: 7th September 2010, 00:05
  3. how to write QT openGL code in two classes
    By qtUse in forum Qt Programming
    Replies: 8
    Last Post: 31st August 2010, 05:41
  4. 1.3.0 - UI Language
    By Asperamanca in forum Qt Tools
    Replies: 2
    Last Post: 16th December 2009, 11:19
  5. How can I add any other language
    By ethos0714 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 22nd February 2006, 02:51

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.