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

Andreas Pakulat apaku at gmx.de
Tue Feb 17 21:25:45 CET 2009


On 17.02.09 13:19:48, Knapp wrote:
> 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.

Sure, that works for extremely simple apps (also in C++, except that you
might need to help moc a bit to find your class declaration inside
main.cpp) but with non-toy apps you don't want all code in one file.

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

Ah, yeah, Qt4.4's designer allows to add connections to slots that don't
yet exists, but will be provided by the class thats given to setupUi().
 
> > 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.

Yeah, often its not too good to learn two things at the same time, or
at least it takes more time and discipline.

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

Its the same thing basically. QtCreator is just a gui that free's you
from running qmake+make manually and obviously provides niceties such as
code-completion and the like.

Andreas

PS: I suggest to not cross-post such questions to the pyqt list and
regarding "getting no answer", its not unusual to have to wait for a few
days for an answer. People are answering here in their spare time often
and that means they answer when they have time and feel like it.

-- 
Don't go surfing in South Dakota for a while.



More information about the Qt-interest-old mailing list