QString: Convert DMS to Decimal degrees and display
-
May you please assist me wiht QString. It is for an assignment - so I cannot change the classes. The compiler says "No matchin fuction to cal for QStriing::QString(const Coordinate&, const Coordinate&)
@
#ifndef GPSCOORD_H
#define GPSCOORD_H
#include <QString>
#include "coordinate.h"class GPSCoord :public Coordinate {
public:
GPSCoord();
void setCoord(int d, int m, int s, char cd);
QString toString(bool decimal) const;private:
Coordinate latitude;
Coordinate longitude;
};
#endif // GPSCOORD_H
//gpscoord.cpp
#include <QString>
#include "gpscoord.h"//no-arg constructor which initialize
GPSCoord::GPSCoord():latitude(0,0,0,'N'),longitude(0,0,0,'E'){}
void GPSCoord::setCoord(int d, int m, int s, char cd){
if ((cd= 'N') or (cd ='S'))
latitude = Coordinate(d,m,s,cd);
else longitude = Coordinate(d,m,s,cd);}
QString GPSCoord::toString(bool decimal)const{
if (decimal == false)
return QString(latitude,longitude);
else
return QString("[%1/%2]").arg(latitude.toString).arg(longitude.toString);
}//coordinate.cpp
#include <QString>
#include "coordinate.h"// constructor
Coordinate::Coordinate():degrees(0),minutes(0), seconds(0), cardinalDirection('N'){ }Coordinate::Coordinate(int d, int m, int s, char cd){
degrees = d;
minutes = m;
seconds = s;
cardinalDirection = 'N';
}QString Coordinate::toString() const{
return QString("%1 %2' %3'' %4").arg(degrees+"° ").arg(minutes+" '").arg(seconds+" ''").arg(cardinalDirection);
}double Coordinate::toDecimal() {
double decimaldgrees = 0.00;
if ((cardinalDirection = 'N') or (cardinalDirection = 'E'))
decimaldgrees = (degrees +(minutes/60)+(seconds/3600));
else
decimaldgrees =-(degrees+(minutes/60)+(seconds/3600));
return decimaldgrees;
}#include "coordinate.h"
#include "gpscoord.h"
#include <QTextStream>int main(){
QTextStream cout(stdout);
Coordinate coord1(20,25,23,'N');
cout<<coord1.degrees<<endl;,
coord1.degrees = (20);
coord1.minutes = (21);
coord1.seconds = (30);
coord1.cardinalDirection = 'N';
coord1.toString();
coord1.toDecimal();
coord1.toString();GPSCoord gpscoord1; gpscoord1.setCoord(15,30,29,'N'); gpsCoord1.toString(); gpscoord1.latitude = (25.23676); gpscoord1.longitude = (23.4567); //cout << strbuf.str;
return 0;
}
@ -
Does it fail in line 37? You have an error there: you are calling members instead of functions. Correct it to:
@
QString("[%1/%2]").arg(latitude.toString()).arg(longitude.toString());
@You have to add "()" ater toString.