Dear fellow Qt progammers,

I am rather new to C++/Qt and programming in general (although I have quite abit bit of experience in scripting languages as bash, Matlab etc.)

As a start, I am writing a program that does conversions between units (e.g. length (km to miles), area (sq m to sq ft) etc.)

1. I have created a small widget that has four fields:
- inputLine (QLineEdit) : input value field
- sourceUnit (QComboBox) : input unit

- resultLine (QLineEdit) : target value field
- targetUnit (QComboBox) : target unit

The goal is that the end user selects input & target unit, and the input value is converted to the target as it is typed (I used a QDoubleValidator to check for a double, and a simple SIGNAL/SLOT to make appear the input immedately in the target value field (without conversion)). At the moment, the units are only placeholders. This worked fine.

Qt Code:
  1. #ifndef DCONVERT_H
  2. #define DCONVERT_H
  3.  
  4. #include <QWidget>
  5.  
  6. class QLineEdit;
  7. class QComboBox;
  8.  
  9. class Dconvert : public QWidget
  10. {
  11. Q_OBJECT
  12.  
  13. public:
  14. Dconvert();
  15.  
  16. public slots:
  17. void convert();
  18.  
  19. private:
  20. QLineEdit *inputLine;
  21. QLineEdit *resultLine;
  22. QComboBox *sourceUnit;
  23. QComboBox *targetUnit;
  24. };
  25. #endif // DCONVERT_H
  26.  
  27.  
  28. #include <QtGui>
  29. #include "dconvert.h"
  30.  
  31. Dconvert::Dconvert()
  32. {
  33. QGroupBox *sourceBox = new QGroupBox(tr("From..."));
  34. QLabel *sourceVal = new QLabel(tr("Value:"));
  35. inputLine = new QLineEdit;
  36. sourceUnit = new QComboBox;
  37.  
  38. sourceUnit->addItem(tr("km"));
  39. sourceUnit->addItem(tr("Nautical mile"));
  40.  
  41. QGroupBox *targetBox = new QGroupBox(tr("To..."));
  42. QLabel *targetVal = new QLabel(tr("Value:"));
  43. resultLine = new QLineEdit;
  44. targetUnit = new QComboBox;
  45.  
  46. targetUnit->addItem(tr("km"));
  47. targetUnit->addItem(tr("Nautical mile"));
  48.  
  49. QPushButton *quitButton = new QPushButton(tr("Quit"));
  50.  
  51. connect(inputLine,SIGNAL(textChanged(QString)),this,SLOT(convert()));
  52.  
  53. QHBoxLayout *inputLayout = new QHBoxLayout;
  54. inputLayout->addWidget(sourceVal);
  55. inputLayout->addWidget(inputLine);
  56. inputLayout->addWidget(sourceUnit);
  57.  
  58. QHBoxLayout *targetLayout = new QHBoxLayout;
  59. targetLayout->addWidget(targetVal);
  60. targetLayout->addWidget(resultLine);
  61. targetLayout->addWidget(targetUnit);
  62.  
  63. QVBoxLayout *mainLayout = new QVBoxLayout;
  64. mainLayout->addLayout(inputLayout);
  65. mainLayout->addLayout(targetLayout);
  66.  
  67.  
  68. setLayout(mainLayout);
  69.  
  70.  
  71. setWindowTitle(tr("DConvert!"));
  72.  
  73.  
  74. }
  75. void Dconvert::convert()
  76. {
  77. resultLine->setText(inputLine->text());
  78. }
To copy to clipboard, switch view to plain text mode 

Next, I want the input string from inputLine to be regarded as a double, to be processed and returned to the resultLine.

Now, here the problems begin:

From QString to double seems to work, but after processing it doesnt.... This must be a very basic problem but I just don't find the solution... help please!

Qt Code:
  1. ...
  2. connect(inputLine,SIGNAL(textChanged(QString)),this,SLOT(convert()));
  3. ...
  4. ...
  5. void Dconvert::convert()
  6. {
  7.  
  8. double *resultaat = new double;
  9. resultaat = (double*) &inputLine->text();
  10. resultLine->setText(QString (*resultaat));
  11. }
To copy to clipboard, switch view to plain text mode 

After compiling, this is the error I receive:

Qt Code:
  1. dconvert.cpp:58: error: conversion from `double' to `QChar' is ambiguous
To copy to clipboard, switch view to plain text mode