Results 1 to 11 of 11

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

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

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

    Hello,
    I want to make program to Nokia phone with using accelerometers. I make new project in Qt Creator. Qt Quick Project->Qt Quick Application. Then Target: Symbian Device, Desktop and Qt Simulator.
    But I have code in QML language. I want to write in C language. What to do?
    Best regards.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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?

    Create a Qt mobile application instead of Qt Quick application.
    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?

    Thanks for answer. I want to write a program to N8 mobile phone which would read accelerometer data and show value on screen at Label.
    I have this code:
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #include <QtGui/QApplication>
    4.  
    5. #include <stdio.h>
    6.  
    7. #define ACCELEROMETER_FILE_N900 "/sys/class/i2c-adapter/i2c-3/3-001d/coord"
    8.  
    9. class Accelerometer {
    10. int x;
    11. int y;
    12. int z;
    13.  
    14. public:
    15. Accelerometer() : x(0), y(0), z(0)
    16. {
    17. update();
    18. }
    19.  
    20. bool update()
    21. {
    22. int tmp[3] = {0, 0, 0};
    23. FILE *fd;
    24.  
    25. if (!(fd = fopen(ACCELEROMETER_FILE_N900, "r"))) {
    26. return false;
    27. }
    28.  
    29. if (fscanf(fd, "%i %i %i", tmp, tmp+1, tmp+2) != 3) {
    30. return false;
    31. }
    32.  
    33. if (fclose(fd) == EOF) {
    34. return false;
    35. }
    36.  
    37. x = tmp[0];
    38. y = tmp[1];
    39. z = tmp[2];
    40.  
    41. //How to change this?
    42. writeln('x=%i',x);
    43. return true;
    44. }
    45.  
    46. int getX() { return x; }
    47. int getY() { return y; }
    48. int getZ() { return z; }
    49.  
    50.  
    51. };
    52.  
    53.  
    54. int main(int argc, char *argv[])
    55. {
    56. QApplication app(argc, argv);
    57. MainWindow mainWindow;
    58. mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
    59. mainWindow.showExpanded();
    60. return app.exec();
    61. }
    To copy to clipboard, switch view to plain text mode 
    The object name of label is label_2. Which code do I have to write to change Label2 text to accelerometer X value? Or what else do I have to write? Or do you have any examples of codes which show on smartphone view acceleration values with only one *.cpp file without any addidtional *.h files?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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?

    Correct me if I'm wrong but N8 is Symbian based, so the path to the accelerometer is incorrect. Why don't you use QSensor from QtMobility instead?
    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
    Aug 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

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

    This page doesn't work. But on site: http://doc.qt.nokia.com/qtmobility-1...lerometer.html there is QML language, which I don't know. I would like to program it in C language. What do you suggest to do in this situation? I found on the internet codes with using accelerometers, but they were with some *.h files and I had lost in this. I would like to write a program with only one main.cpp file and no any header files and 6 Labels in main window: 3 of them- Accelerometer X/Y/Z, and other 3 of them would write actual acceleration. In future I would like to add speed in additional 3 labels.
    Last edited by tom634; 9th August 2011 at 08:54.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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
    This page doesn't work.
    Yes, it doesn't work -- blame autolinking of the site

    Here you go: http://doc.qt.nokia.com/qtmobility-1.2/sensors-api.html

    But on site: http://doc.qt.nokia.com/qtmobility-1...lerometer.html there is QML language, which I don't know. I would like to program it in C language.
    QAccelerometer is a C++ class, not a QML element. The latter is called Accelerometer. And please don't mix C and C++, those are two different languages.
    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.


  7. #7
    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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.


  9. #9
    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 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.


  11. #11
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.