PDA

View Full Version : How to call a function when i clic a button?



trend900
22nd January 2009, 16:24
Yes, i know... very novice.

Im a C# developer, but i want to get out of dotnet asap. I chose QT and bought the book "C++ GUI Programming with Qt 4, Second Edition".

reading the book i have a very noob question: How can i clic a button and then call a funcion as result?. i know is very noob but please be nice, im new to QT (started yesterday).

I was looking at signals and connectios, but this is what i had seen so far:

One signal can be connected to many slots:

Many signals can be connected to the same slot:

A signal can be connected to another signal:

Connections can be removed:

But what i want is to connect a signal to a function. :rolleyes:

Thanks!

spirit
22nd January 2009, 16:30
class MyWidget: public QWidget
{
Q_OBJECT
...
public:
...
private slots:
void processMyButtonClick();
...
};
...
connect(m_myButton, SIGNAL(clicked()), SLOT(processMyButtonClick()));
...
void MyWidget::processMyButtonClick()
{
//do my stuff
}

:)

trend900
22nd January 2009, 16:40
Solved.

Thanks!!