You are not logged in.

#1 2009-04-09 03:06:25

fede
Member
Registered: 2007-06-29
Posts: 126

PyQt: C++ basic literacy to understand Qt docs

Hello,
   
   I am trying to learn PyQt. I can manage fine with my python and basic Qt, but what's bugging me is that there doesn't seem to be so much written about pyqt. I've gone throuth all the tutorials pointed to in pyqt's site, and other places such as learningpython.com. I've read the one up to date book on pyqt4 that I know of: Rapid Gui Programming with Python and Qt by Mark Summerfield.

   My problem is that PyQt's reference seems to be only a basic class reference, while the Qt docs are way more complete, and contain interesting explanations which I have not found in PyQt's docs, and there's also the qt demos and examples. I am spending a lot of time in the Qt docs lately, trying to figure out which Qt class to use, and to understand its basics. But I don't know any c++, so I'm guessing through the workings of the c++ snippets I see. Sometimes this is good enough to point me to the class which I'm looking for, but I can hardly understand anything in any detail when I cannot understand the code.

   So I've been thinking I should try to learn some C++ to be able to understand the docs fully if I want to learn the toolkit in any depth. I love python, I find it amazingly productive and I have a kind of crush on it's syntax. So learning c++ would be only a kind of side project, if it may... The questions I'd like to ask you are:

* Is it possible to gain such thing as a basic knowledge of c++, good enough to understand this kind of docs, without having to go the whole way into c++?

* Do you think it might be worthwile to spend such a time learning a language which from the outside seems a very different beast from the one I use, and which I'm almost certainly bound not to use? (Well, who knows what the future might hold...)

* Could you give me any tips about where to start? Do you know about anything online broadly  analogous to www.diveintopython.org, for example?

   Thanks in advance for your time!

Offline

#2 2009-04-09 03:52:37

dalingrin
Member
Registered: 2009-03-18
Posts: 128

Re: PyQt: C++ basic literacy to understand Qt docs

It really depends on your level of understanding of programming in general. If you have a good understanding of object oriented concepts then learning c++ (at a basic level) should be pretty easy. I'm not saying you'll be whipping out c++ code with any kind of speed but you'll be able to at least follow Qt's documentation.

* Is it possible to gain such thing as a basic knowledge of c++, good enough to understand this kind of docs, without having to go the whole way into c++?

I do think its possible. You really need a good understanding of inheritance but thats about as far as you need to go into c++ for Qt docs.

Have you ever used a statically typed language?

Last edited by dalingrin (2009-04-09 03:56:57)

Offline

#3 2009-04-09 05:13:02

fede
Member
Registered: 2007-06-29
Posts: 126

Re: PyQt: C++ basic literacy to understand Qt docs

I've programmed a bit in pascal back around 1991-93, and a little bit of C a few years later. I think I am quite comfortable with OOP, at least as it's implemented in python - don't know if that involves any great simplifications... From c I remember there were lines with 'side effects' and 3 or 4 things happening at the same time, the concept of pointers, call by reference and by value, though I'm not at all familiar with what this is useful for.

It is quite easy to follow Qt's examples as far as they are calling methods and setting properties, and that has been very useful to me so far. But I wonder if by studying a little bit I could understand code such as the first two lines of this, for example, wehre I've got no idea of what's going on:

void AddressWidget::addEntry(QString name, QString address)
 {
     QList< QPair<QString, QString> >list = table->getList();
     QPair<QString, QString> pair(name, address);

     if (!list.contains(pair)) {
         table->insertRows(0, 1, QModelIndex());

         QModelIndex index = table->index(0, 0, QModelIndex());
         table->setData(index, name, Qt::EditRole);
         index = table->index(0, 1, QModelIndex());
         table->setData(index, address, Qt::EditRole);
         removeTab(indexOf(newAddressTab));
     } else {
         QMessageBox::information(this, tr("Duplicate Name"),
             tr("The name \"%1\" already exists.").arg(name));
     }
 }

Offline

#4 2009-04-09 13:13:02

Zariel
Member
Registered: 2008-10-07
Posts: 446

Re: PyQt: C++ basic literacy to understand Qt docs

I find Qt documentation just as helpful as PyQt's, most of the time PyQt has c++ references in it (I dont know c++) but its not hard to work out once you know the basic c/c++ syntax.

Offline

#5 2009-04-09 13:38:07

mrunion
Member
From: Jonesborough, TN
Registered: 2007-01-26
Posts: 1,938
Website

Re: PyQt: C++ basic literacy to understand Qt docs

This was my best source for help with PyQt. I still ended up having to be a bit familiar with C++ sometimes, but maybe it will help you...

http://www.riverbankcomputing.co.uk/sta … asses.html


Matt

"It is very difficult to educate the educated."

Offline

#6 2009-04-09 14:43:43

dalingrin
Member
Registered: 2009-03-18
Posts: 128

Re: PyQt: C++ basic literacy to understand Qt docs

fede wrote:

I've programmed a bit in pascal back around 1991-93, and a little bit of C a few years later. I think I am quite comfortable with OOP, at least as it's implemented in python - don't know if that involves any great simplifications... From c I remember there were lines with 'side effects' and 3 or 4 things happening at the same time, the concept of pointers, call by reference and by value, though I'm not at all familiar with what this is useful for.

It is quite easy to follow Qt's examples as far as they are calling methods and setting properties, and that has been very useful to me so far. But I wonder if by studying a little bit I could understand code such as the first two lines of this, for example, wehre I've got no idea of what's going on:

void AddressWidget::addEntry(QString name, QString address)
 {
     QList< QPair<QString, QString> >list = table->getList();
     QPair<QString, QString> pair(name, address);

     if (!list.contains(pair)) {
         table->insertRows(0, 1, QModelIndex());

         QModelIndex index = table->index(0, 0, QModelIndex());
         table->setData(index, name, Qt::EditRole);
         index = table->index(0, 1, QModelIndex());
         table->setData(index, address, Qt::EditRole);
         removeTab(indexOf(newAddressTab));
     } else {
         QMessageBox::information(this, tr("Duplicate Name"),
             tr("The name \"%1\" already exists.").arg(name));
     }
 }

I don't think it would hurt to read an overview of C++ then. I started with python then began using c++ because its my school's language of choice. In learning the under workings of c++ I have in the process learned things I can apply with python.
As for those first two lines...
In c++ the syntax

name<datatype>

indicates the use of a template which can be a class or function. A template enables you to write a function or class that can work any data type. In the case above you have a Qt list containing Qt pairs which contain 2 QStrings. You could for instance make a QList of a class that you made like this:

QList<myClass> listOfMyClasses;

In python passing the data type to a class or function isn't needed since it is dynamic typed.

Templates are one tool to eliminate having to write multiple copies of a class or function to work with different datatypes. If I want to write a function that will sum two numbers, instead of writing one function for integers, one for doubles, one for floats...etc I can make a template which can handle all of those data types. (this isn't a very practical use of templates but it is simple one for the sake of discussion) I would call this template function like this:

sum<double>(2.1, 3.2)
//or 
sum<int>(2, 3)

Offline

#7 2009-04-10 05:08:48

fede
Member
Registered: 2007-06-29
Posts: 126

Re: PyQt: C++ basic literacy to understand Qt docs

dalingrin:
Thanks for the answer and the explanation! That is precisely the kind of thing that I'm looking for. What you wrote made me realize that a lot of what was unclear was that assignments are prefixed by the type of the variable when it is not explicitly declared first. I've also been going over the tutorial over at cplusplus.org, it seems very manageable for my purposes.

Great to know about templates, also. Frankly, I think I was freaking out seeing those two lines: with all the '<' and '>' I thought that some dark magic was going on under the hood. Good ol' fear of the unkown.

Well, I hope I'll be catching up on c++ syntax soon. Thanks again for your support.

matt:

Thanks for the tip, I've been using those quite frequently, but they seem to be an incomplete copy of the version over at qt. For instance, links to examples & demos are broken. Also, the code is written in c++ so while it's readable insofar as documenting class methods and properties goes, it is precisely the reason of my desire for a bit of c++ literacy.

Offline

Board footer

Powered by FluxBB