Hallo,
ich versuche mich gerade an einem kleinen C++ Programm in Kombination mit Qt. Die Qt Anbindung ist auch gerade gar nicht das Problem, viel mehr funktioniert die Rückgabe einer Struktur als Referenz nicht.
Hier erst einmal der Quelltext:
mainwindowimpl.h
und mainwindowimpl.cpp
Das Problem besteht nun darin, das innerhalb von makeGpsData ich die Struktur so nicht zurückgeben darf. Ich verstehe allerdings mal wieder nicht wieso ich das so nicht machen kann.
Hier vielleicht noch die Fehlermeldung die bekomme:
Beide Fehler scheinen ja die selbe Ursache zu haben.
Schon vorab vielen Dank!
Gruß
WingMan
ich versuche mich gerade an einem kleinen C++ Programm in Kombination mit Qt. Die Qt Anbindung ist auch gerade gar nicht das Problem, viel mehr funktioniert die Rückgabe einer Struktur als Referenz nicht.
Hier erst einmal der Quelltext:
mainwindowimpl.h
C++:
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include <iostream>
#include <string>
#include <QMainWindow>
#include <QFileDialog>
#include <QFile>
#include <QDate>
#include "ui_mainwindow.h"
using namespace std;
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private:
void setFileText();
void setContentText();
struct gpsData* makeGpsData(QString str);
enum enumFixedStatus
{
ACTIVE, INVALID
};
enum enumLatHemisphere
{
NORTH, SOUTH
};
enum enumLonHemisphere
{
EAST, WEST
};
struct gpsData
{
//std::string commandWord;
QString sCommandWord;
float fDerivedTime;
enum enumFixedStatus eFixedStatus;
float fLatDecimalDegrees;
enum enumLatHemisphere eLatHemisphere;
float fLonDecimalDegrees;
enum enumLatHemisphere eLonHemisphere;
float fSpeed;
float fBearing;
QDate UTCdate;
int iChkSum;
};
QString strFileContent;
QString strFileName;
QList <struct gpsData> listGpsData;
private slots:
void FileOpen();
};
#endif
und mainwindowimpl.cpp
C++:
#include "mainwindowimpl.h"
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
QObject::connect(butFileOpen, SIGNAL(clicked()), this, SLOT(FileOpen()));
}
void MainWindowImpl::FileOpen()
{
strFileName = QFileDialog::getOpenFileName(this, "Select a GPS logfile");
if(!strFileName.isEmpty())
{
QFile file(strFileName);
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
strFileContent = file.readAll();
setFileText();
setContentText();
}
}
}
void MainWindowImpl::setFileText()
{
txtFileContent->setText(strFileContent);
}
void MainWindowImpl::setContentText()
{
struct gpsData* gps;
int startLine = 0;
for(int i = 0; i < strFileContent.length(); i++)
{
if(strFileContent[i] == '\n')
{
gps = makeGpsData(strFileContent.mid(startLine, i-1));
startLine = i+1;
}
}
}
struct gpsData* MainWindowImpl::makeGpsData(QString str)
{
struct gpsData* gps = new (struct gpsData);
gps->sCommandWord = str;
return gps;
}
Das Problem besteht nun darin, das innerhalb von makeGpsData ich die Struktur so nicht zurückgeben darf. Ich verstehe allerdings mal wieder nicht wieso ich das so nicht machen kann.
Hier vielleicht noch die Fehlermeldung die bekomme:
Code:
src/mainwindowimpl.cpp: In member function »void MainWindowImpl::setContentText()«:
src/mainwindowimpl.cpp:40: Fehler: »gpsData*« kann nicht nach »MainWindowImpl::gpsData*« in assignment umgewandelt werden
src/mainwindowimpl.cpp: In member function »gpsData* MainWindowImpl::makeGpsData(QString)«:
src/mainwindowimpl.cpp:50: Fehler: »MainWindowImpl::gpsData*« kann nicht nach »gpsData*« in return umgewandelt werden
Beide Fehler scheinen ja die selbe Ursache zu haben.
Schon vorab vielen Dank!
Gruß
WingMan