aus slot konstruktor aufrufen
aus slot konstruktor aufrufen
hallo,
ich möchte aus einer slotroutine einen konstruktor aufrufen und dabei einen integer wert übergeben. kann mir da jemand helfen.
volture
ich möchte aus einer slotroutine einen konstruktor aufrufen und dabei einen integer wert übergeben. kann mir da jemand helfen.
volture
also irgendwie bekomme ich das nicht hin. schein zu dumm zu sein.
also:
meine ..ui.h
void mainWindow::Slot(int a)
{
Dialog aufruf;
aufruf.setA(a);
Dialog * pDlg = new Dialog(this, "dialog");
pDlg->exec();
}
meine..h
class Dialog : public dialog
{
Q_OBJECT
private:
int k;
public:
Dialog( QWidget* parent = 0, const char* name = 0);
~Dialog();
setA(int a)
{
k=a;
};
};
meine ...cpp
Dialog::Dialog( QWidget* parent, const char* name)
: dialog( parent, name)
{
test->setNum(k);
}
die ausgabe der variable k stimmt nicht mit der ursprungsvariable a überein.
kann mir jemand den fehler sagen.
danke volture
also:
meine ..ui.h
void mainWindow::Slot(int a)
{
Dialog aufruf;
aufruf.setA(a);
Dialog * pDlg = new Dialog(this, "dialog");
pDlg->exec();
}
meine..h
class Dialog : public dialog
{
Q_OBJECT
private:
int k;
public:
Dialog( QWidget* parent = 0, const char* name = 0);
~Dialog();
setA(int a)
{
k=a;
};
};
meine ...cpp
Dialog::Dialog( QWidget* parent, const char* name)
: dialog( parent, name)
{
test->setNum(k);
}
die ausgabe der variable k stimmt nicht mit der ursprungsvariable a überein.
kann mir jemand den fehler sagen.
danke volture
Der Konstrucktor wird ja immer als erstes aufgerufen also vor der Funktionvolture hat geschrieben:
void mainWindow::Slot(int a)
{
// Dialog aufruf;
// aufruf.setA(a);
Dialog * pDlg = new Dialog(this, "dialog");
pDlg->setA( a );
pDlg->exec();
}
setA( a ); daher kann man meiner meinung nach so im Konstrucktor
auch nicht auf a zugreifen ( es ist fraglich ob man das überhaupt braucht )
man könnte allerdings den Konstrucktor um eine Variable a erweitern
Dialog * pDlg = new Dialog(this, "dialog", a);
pDlg->setA( a );
pDlg->exec();
----------- Schnipp ------------------
private:
int k;
public:
Dialog( QWidget* parent = 0, const char* name = 0, int a = 0 );
~Dialog();
------------- Schnapp ---------------------------------------
-------------- Schnipp ---------------------
Dialog::Dialog( QWidget* parent, const char* name, int a )
: dialog( parent, name), k(a)
{
test->setNum(k);
}
------------ Schnapp ---------------------------