[Qt-interest] Newbie question about setting a simple signal and slot with creator based code.
Andreas Pakulat
apaku at gmx.de
Tue Feb 17 10:42:29 CET 2009
On 16.02.09 22:39:22, Knapp wrote:
> I had all this understood and working well in pyQT but here I am lost.
> Creator has made a working gui and I want to add a custom signal and
> slot and its method.
> I have the files main.cpp
> mainwindow.cpp
> mainwindow.h
> ui_mainwindow.h
>
> So the first question is where do I put it? In python the custom stuff
> would be in main.cpp (of sorts)
No it wouldn't end in main.py in PyQt. It would land in whatever you name
the module that contains your subclasses from QMainWindow/QLabel/QSlider.
And its the same thing in C++, mainwindow.h provides a QMainWindow subclass
into which you can declare any signal or slot, that you want to emit from
objects of your mainwindow class.
> The next question is what is the code exactly?
class MyMainWindow : public QMainWindow
{
Q_OBJECT
....
signals:
void mysignal();
private slots:
void myslot();
};
> Lets say I have a MYslider and MYlabel. Slide the slider making an int
> signal and put 2 times that amount into the MYlabel.
Then connect the sliders changed signal to a slot in your mainwindow and
update the label via the setText method.
> I have read lots of tutorials but am still lost, do to my weak C++.
Then you might want to first improve your C++ skills, unfortunately I don't
have a good suggestion for a book as I've learned the basics myself only
from try'n'error and reading existing code.
BTW: all the example apps that come with Qt have a lot of signal slot
connections done in code, so you should be able to learn from them.
Andreas
--
Give him an evasive answer.
More information about the Qt-interest-old
mailing list