Seite 1 von 1

Ist der namespace das Problem?

Verfasst: 12. September 2005 19:15
von pumbah
g++ -I... -L... -lqt ...

Output:

**********************************************************************************************
Keyboard.cpp: In constructor `Keyboard::Keyboard(QWidget*, const char*)':
Keyboard.cpp:7: error: initializer list being treated as compound expression
Keyboard.cpp:7: error: cannot convert `Keyboard* const' to `Qt::Key' in
initialization
main_Keyboard.cpp: In function `int main(int, char**)':
main_Keyboard.cpp:8: error: statement cannot resolve address of overloaded
function
***********************************************************************************************

Wieso erkennt der g++ Key als Unterklasse von Qt::
Warum kann er die Adresse nicht auflösen?


Input:

###########main.cpp #################

#include <qapplication.h>
#include "Keyboard.h"

int main(int argc, char ** argv)
{
QApplication a(argc, argv);
Keyboard *kb = new Keyboard();
kb->show;
return a.exec();
}

################# key.h ####################
#ifndef KEY_H
#define KEY_H

#include <qpushbutton.h>

class Key : public QPushButton
{
public:
// Key( QWidget * parent, const char * name = 0 );
Key( int val, const QString & text, QWidget * parent, const char * name);
~Key();
private:
int value;
};
#endif //KEY_H

################ key.cpp ##################
#include "Key.h"
#include <qpushbutton.h>

/* Key::Key( QWidget * parent, const char * name = 0 )
: QPushButton(parent, name) ;
*/
Key::Key( int val = 0, const QString & text = 0, QWidget * parent = 0, const char * name = 0 ) : QPushButton(text, parent, name)
{
value = val;
}
Key::~Key()
{
}

################ keyboard.h ################
#ifndef KEYBOARD_H
#define KEYBOARD_H

#include <qwidget.h>
#include "Key.h"

class Keyboard : public QWidget
{

public:
Keyboard( QWidget* parent = 0, const char* name = 0);
~Keyboard();

private:


};

#endif // KEYBOARD_H
################ keyboard.cpp ##############
#include "Keyboard.h"
#include "Key.h"

Keyboard::Keyboard( QWidget* parent, const char* name)
: QWidget(parent, name)
{
Key *k = new Key(13, "Hello World", this);
}
Keyboard::~Keyboard()
{
}
#########################################
cu,

Pumbah

Verfasst: 13. September 2005 08:39
von lepsai
du must Key umbenennen, z.B. in MyKey, dann geht's....

Verfasst: 13. September 2005 18:30
von pumbah
Hi,

also gibt es bereits ein Objekt mit dem Namen!?

Dank' Dir,

pumbah

Verfasst: 13. September 2005 18:31
von lepsai
ja, Qt::Key

Verfasst: 13. September 2005 18:52
von dani
<blödFrag>Und wofür gibts dann den Namespace?</blödFrag>

Verfasst: 13. September 2005 19:24
von lepsai
Qt ist kein namespace sondern Basisklasse für alle Qt-Klassen

Verfasst: 13. September 2005 19:35
von dani
Sorry, ich hab in Qt4 gedacht. Im Thread wird die Version nirgens erwähnt (oder ich bin blind). Bei Qt3 war das ja noch kein Namespace... :oops: