Results 1 to 17 of 17

Thread: Lots of beginner doubts

  1. #1
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Lots of beginner doubts

    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:
    Qt Code:
    1. #include<QApplication>
    2. #include<QFont>
    3. #include<QPushButton>
    4. class quitwidget:public QWidget
    5. {
    6. public:
    7. quitwidget(QWidget *parent=0):QWidget(parent)
    8. {
    9. QPushButton p("hey",this);
    10. // p is a child widget of calling widget
    11. // p.setFont(QFont("Times",80,QFont::Bold));
    12. //p.setGeometry(62,40,75,30);
    13. //since it does not know abt qapp object we connect it to QApp pointer
    14. connect( &p, SIGNAL(clicked()), qApp, SLOT(quit()) );
    15. //QLabel l("Hello");
    16. p.show();
    17. }
    18. };
    19.  
    20. int main(int argc,char *argv[])
    21. {
    22. QApplication a( argc, argv );
    23. quitwidget q(&w);
    24. //q.setGeometry( 100, 100, 200, 120 );
    25. w.show();
    26. return a.exec();
    27. }
    To copy to clipboard, switch view to plain text mode 
    3.any way to host qt applications online?
    Thanks..

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Lots of beginner doubts

    Quote Originally Posted by Nishant View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    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>

  4. #4
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    Well corrected the code...The last thing i was asking is like...Could you suggest some efficent resources to learn QT effectively

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    Quote Originally Posted by Nishant View Post
    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?

  6. #6
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    Well dont you think its much cumbersome to change the case now and then??

  7. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    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.

  8. #8
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    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?

  9. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    Quote Originally Posted by Nishant View Post
    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.

  10. #10
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    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)

  11. #11
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Lots of beginner doubts

    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.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  12. #12
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

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

  13. The following user says thank you to squidge for this useful post:

    john_god (24th December 2009)

  14. #13
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Lots of beginner doubts

    I didnt know about Ctrl+Space. Thanks.
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Lots of beginner doubts

    Quote Originally Posted by Nishant View Post
    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
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #15
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Lots of beginner doubts

    Quote Originally Posted by Nishant View Post
    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

  17. #16
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    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

  18. #17
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Lots of beginner doubts

    Did you untick "Case-sensitive completion" and include the appropriate header file ?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.