PDA

View Full Version : Lots of beginner doubts



Nishant
22nd December 2009, 11:08
Hello all,
I am a beginner in Qt.Please clarify:
1.Why is the indentation so made(like QApplication.....etc)
2.the following code does not show any output:


#include<QApplication>
#include<QFont>
#include<QPushButton>
class quitwidget:public QWidget
{
public:
quitwidget(QWidget *parent=0):QWidget(parent)
{
QPushButton p("hey",this);
// p is a child widget of calling widget
// p.setFont(QFont("Times",80,QFont::Bold));
//p.setGeometry(62,40,75,30);
//since it does not know abt qapp object we connect it to QApp pointer
connect( &p, SIGNAL(clicked()), qApp, SLOT(quit()) );
//QLabel l("Hello");
p.show();
}
};

int main(int argc,char *argv[])
{
QApplication a( argc, argv );
QWidget w;
quitwidget q(&w);
//q.setGeometry( 100, 100, 200, 120 );
w.show();
return a.exec();
}

3.any way to host qt applications online?
Thanks..

wysota
22nd December 2009, 11:35
1.Why is the indentation so made(like QApplication.....etc)
I don't understand the question. If you are asking why we indent code then we do it because it is easier to read it when it is indented than when it is not. Indentation is not obligatory.


2.the following code does not show any output:
Your button object goes out of scope as soon as the constructor returns.

3.any way to host qt applications online?

If you mean something like an applet - you can write Qt apps in Java (with the help of Jambi). If you're asking about means of placing an app somewhere it can be downloaded and executed locally, just provide a link to the application on your webpage.

Nishant
22nd December 2009, 11:57
Hey thanks for reply.
1.about indentation i meant that why is it kept like
QApplication and not as qapplication....for other examples take QHBoxLayout and not qhboxlayout
2.How do i rectify it<that code>

Nishant
22nd December 2009, 12:08
Well corrected the code...The last thing i was asking is like...Could you suggest some efficent resources to learn QT effectively

squidge
22nd December 2009, 13:58
Hey thanks for reply.
about indentation i meant that why is it kept like QApplication and not as qapplication....for other examples take QHBoxLayout and not qhboxlayout
C/C++ is case sensitive, so once you have written it once in one case, you have to use that case for entire project. Don't you agree however that QHBoxLayout looks and reads easier than qhboxlayout?

Nishant
23rd December 2009, 14:23
Well dont you think its much cumbersome to change the case now and then??

squidge
23rd December 2009, 20:50
I don't get what you mean? The case doesn't change, for objects like QApplication, the case is set in stone. You can't change it, you HAVE to use that casing. Therefore all applications use the same word EXACTLY, including the same case.

Secondly, QtCreator supports code completion. So if you type qapp, it automatically suggests QApplication, and if you type qhb, it will suggest QHBoxLayout, etc. You don't need to remember the case of every letter, although most times its quite obvious.

Nishant
24th December 2009, 03:38
i meant that to type QHBoxLayout...and others you need to shift from lower case to uppercase while typing ...this very thing i don't like...do you get my prob now?

squidge
24th December 2009, 09:51
i meant that to type QHBoxLayout...and others you need to shift from lower case to uppercase while typing ...this very thing i don't like...Then don't do it? Like I said above, if you type qhb (all lower case), then QtCreator will offer "QHBoxLayout" as a suggestion for you and you can just select that.

Nishant
24th December 2009, 11:08
Well, i understand that my doubt is too silly.but my editor doesn't suggest QHBoxLayout on typing qhb:have i turned anything off or m using the other version...
in the about qt creator tab my qt creator says :
Qt Creator 1.2.1
Based on Qt 4.5.3 (32 bit)

john_god
24th December 2009, 11:48
My editor QTCreator doesnt suggest that either, but if I have a object of a Qt class, when using that object it will suggest the object methods, even if those methods are uppercase and I am typing in lowercase. If you prefer lowercase typing you can use it for your variables and class names, althought I think ist not a big deal using "Fisrt Letter Uppercase" writting. ;)

squidge
24th December 2009, 15:23
Maybe some settings need modification on your version of QtCreator. Goto tools->Options->Text Editor->Completion and untick "Case-sensitive completion".

Then type 'qhb' and press Ctrl+Space. You should notice that 'qhb' gets changed to 'QHBoxLayout'. This will also work for all your own variables too, so you could have one like 'MyVeryLongVariableName' and then just type 'my' and Ctrl+Space. If there's more than one match, it'll list them.

So now theres no need not to have long descriptive variable names :)

Personally, I prefer the first letter lower case, and then each additional part upper case. Eg. 'lastActionState'.

john_god
24th December 2009, 15:55
I didnt know about Ctrl+Space. Thanks.

wysota
27th December 2009, 09:48
i meant that to type QHBoxLayout...and others you need to shift from lower case to uppercase while typing ...this very thing i don't like...do you get my prob now?

It's a coding convention. You just have to live with that. Of course you can typedef every class in Qt to lowercase only but this wouldn't make much sense. And the code would be completely unreadable. The general tendency in C++ (and OOP in general) is that class names should start with a capital letter.

See this as well: http://en.wikipedia.org/wiki/CamelCase

schnitzel
27th December 2009, 20:31
Well corrected the code...The last thing i was asking is like...Could you suggest some efficent resources to learn QT effectively

have you looked at Qt documentation. It features an abundance of guides/tutorials/samples:
http://doc.qt.nokia.com/4.6/

There is a reference to an online book on this page which might be worth checking out:
http://doc.qt.nokia.com/4.6/how-to-learn-qt.html

Nishant
29th December 2009, 15:43
Hey its still not working when i type qhb and press ctrl + space...
i am using
Qt Creator 1.2.1
Based on Qt 4.5.3 (32 bit)

Built on Sep 30 2009 at 05:21:42

squidge
29th December 2009, 16:18
Did you untick "Case-sensitive completion" and include the appropriate header file ?