Re: newby c++ & Qt : connect
Quote:
Q1.) can i connect a signal in myData with a Slot in myMessageBox without passing through MainWindow? the only thing they got in common is the same parent.
Connection between a SIGNAL of myData and SLOT of myMessageBox better be made in MainWindow.
Quote:
Q2.) how do i get access from myMessageBox to myData. i tried something like :
Don't do this, myData should not access myMessageBox, this is the whole point of SIGNAL and SLOTS, objects need not know each other.
BTW just a small correction in code
Code:
void myDataClass
::setData(QString *s
) {
if(str)
delete str; //<<<<<<<<<<<<<<<<<<<<<
str = s;
emit DataChanged();
}
Re: newby c++ & Qt : connect
thanks for your fast reply and the correction.
so all the connects shall be mad in the MainWindow ( in my case) ??
on the one hand i have a gui that is fed by the user and everything he/she enters shall be written in my data.
how i woud do it for now:
the Gui widget emits a signal which will be cought by the main window by the corresponding public slot. this slot is then connected o the main windows funktion that calls the guiWidget with a pointer to the dataObject. this seems really complicated if you have a lot of GuiWidgets; or what i don't undestand?
Re: newby c++ & Qt : connect
Quote:
...this slot is then connected o the main windows funktion that calls the guiWidget with a pointer to the dataObject.
This is not a good idea. Instead pass the value in the signal as a parameter.
Re: newby c++ & Qt : connect
Not entirely related, but don't use QString pointers. QStrings can easily and cheaply be copied around, raw pointers tend to leak.
Cheers,
_
Re: newby c++ & Qt : connect
hi,
Quote:
i'm trying to understand the Signal Slot mechanism of Qt
Create a simple pushbutton and try to connect with a slot.
To understand signals, you shall subclass QPushButton and add your own signal.
ex:
Code:
slot:
class myClass
{
..............
................
SLOTS:
void clickSlot();
}
........................
connect(btn,clicked(clicked()),this,SLOT(clickSlot()));
........................
hope it helps,
Bala