QLineEdit -> was not declared in this scope

Alles rund um die Programmierung mit Qt
Antworten
rdg
Beiträge: 9
Registriert: 27. August 2007 16:39

QLineEdit -> was not declared in this scope

Beitrag von rdg »

Hi,

erstmal vorweg, ich habe erst vor kurzem mit qt begonnen und habe auch noch nicht so viel Praxis in C++. "Aller anfang ist schwer".
Deshalb habe ich mir das Buch Qt 4 von open source press gekauft.

Dort habe ich ein Bespiel bekommen:

Code: Alles auswählen

class ByteConverterDialog : public QDialog{

	Q_OBJECT

public:
	ByteConverterDialog();
private:
	QLineEdit* decEdit;
	QLineEdit* hexEdit;
	QLineEdit* binEdit;
};

ByteConverterDialog::ByteConverterDialog(){
	QVBoxLayout* mainLayout = new QVBoxLayout(this);
	QGridLayout* editLayout = new QGridLayout;
	QHBoxLayout* buttonLayout = new QHBoxLayout(this);

	mainLayout->addLayout(editLayout);
	mainLayout->addStretch();
	mainLayout->addLayout(buttonLayout);
	
	QLabel* decLabel = new QLabel(tr("Dezimal"));
	QLabel* hexLabel = new QLabel(tr("Hexadezimal"));
	QLabel* binLabel = new QLabel(tr("Binär"));
	decEdit = new QLineEdit;
	hexEdit = new QLineEdit;
	binEdit = new QLineEdit;

	editLayout->addWidget(decLabel,0,0);
	editLayout->addWidget(decEdit,0,1);
	editLayout->addWidget(hexLabel,1,0);
	editLayout->addWidget(hexEdit,1,1);
	editLayout->addWidget(binLabel,2,0);
	editLayout->addWidget(binEdit,2,1);

	QPushButton* exitButton = new QPushButton(tr("Beenden"));

	mainLayout->addStretch();
	mainLayout->addLayout(exitButton);
}
Doch ich bekomme beim übersetzen leider:
ByteConverterDialog.h:13: error: ISO C++ forbids declaration of ‘QLineEdit’ with no type
ByteConverterDialog.h:13: error: expected ‘;’ before ‘*’ token
...
ByteConverterDialog.cpp:21: error: ‘decEdit’ was not declared in this scope
...

Deshalb meine Frage an Euch, was mache ich falsch? Über Eure Ideen bin ich sehr sehr dankbar.

dank und gruß
rdg

/edit bei Christian81 - [

Code: Alles auswählen

] - Tags eingefügt. Bitte Foren-Doku lesen bevor man postet!
upsala
Beiträge: 3946
Registriert: 5. Februar 2006 20:52
Wohnort: Landshut
Kontaktdaten:

Beitrag von upsala »

ein

Code: Alles auswählen

#include <QLineEdit>
oder

Code: Alles auswählen

#include <QtGui>
ist aber schon irgendwo enthalten?
nando
Beiträge: 321
Registriert: 28. Oktober 2004 13:16

Beitrag von nando »

Forward declaration im headerfile...???

class LineEdit;
rdg
Beiträge: 9
Registriert: 27. August 2007 16:39

Beitrag von rdg »

erstmal danke an euch dass Ihr euch meinem Problem annimmt.
sory hatte versucht es kurz darzustellen, hier noch einmal der gesammte code:

//ByteConverterDialog .h
#ifndef BYTECONVERTERDIALOG_H
#define BYTECONVERTERDIALOG_H

#include <QDialog>

class ByteConverterDialog : public QDialog{

Q_OBJECT

public:
ByteConverterDialog();
private:
QLineEdit* decEdit;
QLineEdit* hexEdit;
QLineEdit* binEdit;
};
#endif




//ByteConverterDialog.cpp
#include "ByteConverterDialog.h"
#include <QLabel>
#include <QLineEdit>
#include <QtGui>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>

ByteConverterDialog::ByteConverterDialog(){
QVBoxLayout* mainLayout = new QVBoxLayout(this);
QGridLayout* editLayout = new QGridLayout;
QHBoxLayout* buttonLayout = new QHBoxLayout(this);

mainLayout->addLayout(editLayout);
mainLayout->addStretch();
mainLayout->addLayout(buttonLayout);

QLabel* decLabel = new QLabel(tr("Dezimal"));
QLabel* hexLabel = new QLabel(tr("Hexadezimal"));
QLabel* binLabel = new QLabel(tr("Binär"));
decEdit = new QLineEdit;
hexEdit = new QLineEdit;
binEdit = new QLineEdit;

editLayout->addWidget(decLabel,0,0);
editLayout->addWidget(decEdit,0,1);
editLayout->addWidget(hexLabel,1,0);
editLayout->addWidget(hexEdit,1,1);
editLayout->addWidget(binLabel,2,0);
editLayout->addWidget(binEdit,2,1);

QPushButton* exitButton = new QPushButton(tr("Beenden"));

mainLayout->addStretch();
mainLayout->addLayout(exitButton);
}
RD1978
Beiträge: 84
Registriert: 5. Juni 2007 08:00
Wohnort: Stralsund (DDR)

Beitrag von RD1978 »

Hallo,
Forward declaration im headerfile...???
in der Header Datei:

Code: Alles auswählen

//ByteConverterDialog .h
#ifndef BYTECONVERTERDIALOG_H
#define BYTECONVERTERDIALOG_H

#include <QDialog>

class QLineEdit;

class ByteConverterDialog : public QDialog{

Q_OBJECT

public:
ByteConverterDialog();
private:
QLineEdit* decEdit;
QLineEdit* hexEdit;
QLineEdit* binEdit;
};
#endif
MfG RD1978
rdg
Beiträge: 9
Registriert: 27. August 2007 16:39

Beitrag von rdg »

Ja das war es vielen dank !!! :D :D :D
Antworten