Results 1 to 4 of 4

Thread: Little issue when trying to use a value as a function

  1. #1
    Join Date
    Mar 2011
    Location
    Narvik, Norway
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Little issue when trying to use a value as a function

    Hi, I am sorry if this is a very noobish question but I have tried to create a speed-o-meter from the clock example posted somewhere on this site.

    This is my code so far in that class:
    Qt Code:
    1. #include <QtGui>
    2. #include "graphview.h"
    3. #include "mainwindow.h"
    4. #include "paramwidget.h"
    5. #include "connectbar.h"
    6. #include "mapwidget.h"
    7. #include "speedometer.h"
    8.  
    9.  
    10.  
    11. SpeedoMeter::SpeedoMeter(QWidget *parent)
    12. : QWidget(parent), mdir("messages.txt")
    13. {
    14.  
    15.  
    16.  
    17. // QTimer *timer = new QTimer(this);
    18. // connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    19. // timer->start(1000);
    20.  
    21. setWindowTitle(tr("Speed-O-Meter"));
    22. resize(200, 200);
    23. }
    24.  
    25. void SpeedoMeter::paintEvent(QPaintEvent *)
    26. {
    27.  
    28.  
    29. GraphView* velocity = new GraphView(mdir.getMsgInfo("VELOCITY"), mdir.getMsgInfo("UTC"));
    30. //float velocity = _minfo->getFloat(msg);
    31.  
    32.  
    33.  
    34.  
    35.  
    36.  
    37. static const QPoint hourHand[3] = {
    38. QPoint(7, 8),
    39. QPoint(-7, 8),
    40. QPoint(0, -40)
    41. };
    42. // static const QPoint minuteHand[3] = {
    43. // QPoint(7, 8),
    44. // QPoint(-7, 8),
    45. // QPoint(0, -70)
    46. // };
    47.  
    48. QColor hourColor(0, 191, 255);
    49. // QColor minuteColor(0, 127, 127, 191);
    50.  
    51. int side = qMin(width(), height());
    52. // QTime time = QTime::currentTime();
    53.  
    54. QPainter painter(this);
    55. painter.setRenderHint(QPainter::Antialiasing);
    56. painter.translate(width() / 2, height() / 2);
    57. painter.scale(side / 200.0, side / 200.0);
    58.  
    59. painter.setPen(Qt::NoPen);
    60. painter.setBrush(hourColor);
    61.  
    62. painter.save();
    63. painter.rotate(12.0 * ((velocity(0))));
    64. painter.drawConvexPolygon(hourHand, 3);
    65. painter.restore();
    66.  
    67. painter.setPen(hourColor);
    68.  
    69. for (int i = 0; i < 12; ++i) {
    70. painter.drawLine(88, 0, 96, 0);
    71. painter.rotate(30.0);
    72. }
    73.  
    74. //painter.setPen(Qt::NoPen);
    75. //painter.setBrush(minuteColor);
    76.  
    77. //painter.save();
    78. // painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
    79. //painter.drawConvexPolygon(minuteHand, 3);
    80. //painter.restore();
    81.  
    82. //painter.setPen(minuteColor);
    83.  
    84. // for (int j = 0; j < 60; ++j) {
    85. // if ((j % 5) != 0)
    86. // painter.drawLine(92, 0, 96, 0);
    87. //painter.rotate(6.0);
    88. //}
    89. }
    To copy to clipboard, switch view to plain text mode 

    I get the following error when I try to run it 'velocity' cannot be used as a function.
    but thats exactly what I want, the line
    Qt Code:
    1. GraphView* velocity = new GraphView(mdir.getMsgInfo("VELOCITY"), mdir.getMsgInfo("UTC"));
    To copy to clipboard, switch view to plain text mode 
    is used in one of my other classes to decleare a widget and then I place the widget out on my main windows and I get a value from it (speed), this value I want to use in my speedometer so that it looks like a cool analog speedometer and not just the value.

    any sugestions?

    thanks.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Little issue when trying to use a value as a function

    Line 63 :
    Qt Code:
    1. painter.rotate(12.0 * ((velocity(0))));
    To copy to clipboard, switch view to plain text mode 
    what do You want to do ???

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Little issue when trying to use a value as a function

    The needle on the dial should be rotated by some amount proportional to the velocity before being drawn. Commented line 30 with its float velocity looks like a better, though not correct, fit to line 63. The constant 12.0 is coming from the 12-hour clock this was cut-n-pasted from.

  4. #4
    Join Date
    Mar 2011
    Location
    Narvik, Norway
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Little issue when trying to use a value as a function

    Hi,
    I think I am giving upp on that project since it might be that the vehicle goes a bit to fast for a 360 degrees visualization, but now I want to make this code to be a roll meter instead, to see if the vehicle is horizontal or in a roll, if you know what I mean, like in flightsimulator =) (----) or (not horizontal line).

Similar Threads

  1. Replies: 7
    Last Post: 9th December 2010, 22:26
  2. Replies: 2
    Last Post: 13th September 2010, 20:03
  3. Replies: 3
    Last Post: 25th May 2010, 09:46
  4. Replies: 0
    Last Post: 10th March 2010, 08:13
  5. Zip function for Qt4
    By devilj in forum Newbie
    Replies: 7
    Last Post: 15th July 2007, 14:37

Tags for this Thread

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.