[Qt-interest] Newbie question about setting a simple signal and slot with creator based code.

Knapp magick.crow at gmail.com
Tue Feb 17 13:19:48 CET 2009


First, thanks for the answer!! I was starting to think no one would
answer. I also found an answer of sorts on youtube of all places. It
at least got my program working to follow this pattern of placement
and got me over the hurdle of what code I needed.
http://www.youtube.com/watch?v=QLT7oEt6gLE&feature=related

On Tue, Feb 17, 2009 at 10:42 AM, Andreas Pakulat <apaku at gmx.de> wrote:
> 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.

In my python code .ui gets turned into a file called Char.py by thu
pyuic program.
Then I write one called CharRun.py this has the main call and the
subclass with its init that sets up the connection of the slots, and
the very short main program at the end that ties it all together.
There is also a CharResources.py file but that is include by Char.py
so I don't have to think about it.

> 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.

I ended up putting the prototypes in mainwindow.h in the mainwindow
class and then the code is in mainwindow.cpp. The connection line was
not done by me in this case but by the UI program when I added my own
slot while making a connection. Perhaps I could have done this in
python too but did not know that.

>> The next question is what is the code exactly?

yes, code like this is in my mainwindow.h
and then the real code is in mainwindow.cpp (as is normal in c++)

> 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.

I found a really good tutorial for c++ on the net. The real problem is
somewhere between understanding C++ classes and understanding QT. At
least I have a working program now! Thanks for you help!! Sometimes
the getting over that last hump is really hard but everyone things it
looks so easy that they don't help.

http://www.cplusplus.com/doc/tutorial/

> 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.

Reading their code and making it work was easy. Understanding the
format that was expected with Creator was not.

> Andreas

-- 
Douglas E Knapp

Why do we live?



More information about the Qt-interest-old mailing list