Results 1 to 12 of 12

Thread: QtTraining-Your First Qt Application

  1. #1
    Join Date
    Jan 2011
    Location
    China->Nanjing
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QtTraining-Your First Qt Application

    How to achive this?Can someone help me?

    Please see the Attachments!

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QWidget window; // our top-level window
    8.  
    9. // ... your code here
    10.  
    11. window.resize(480, 640);
    12. window.show();
    13.  
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Thankyou Very Much!
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtTraining-Your First Qt Application

    what do you want to do?

  3. The following user says thank you to FelixB for this useful post:

    dagobert1989 (13th January 2011)

  4. #3
    Join Date
    Jan 2011
    Location
    China->Nanjing
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtTraining-Your First Qt Application

    Please see the attachments.
    Thanks!

  5. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtTraining-Your First Qt Application

    you don't want us to give you the complete code, do you?

    I'd suggest:
    First, you search appropriate QWidgets.
    Second, you read about QLayouts.

    you can ask specific questions, of course.
    Felix

  6. The following user says thank you to FelixB for this useful post:

    dagobert1989 (13th January 2011)

  7. #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: QtTraining-Your First Qt Application

    The easiest way to achieve that is to use Qt Designer. Select your widgets, drag them on the form and repeat until you have the same window as shown in your attachment.

    Of course, it will not be functional, but then again, neither is a screenshot.

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

    dagobert1989 (13th January 2011)

  9. #6
    Join Date
    Jan 2011
    Location
    China->Nanjing
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtTraining-Your First Qt Application

    Yeah.
    I write some codes.But it didn't work.
    Can you give me some tips?
    How can I make it right.
    Please tell me how.
    Qt Code:
    1. /*************************************************************************
    2.  *
    3.  * Copyright (c) 2008-2011, Nokia Corporation and/or its subsidiary(-ies).
    4.  * All rights reserved.
    5.  *
    6.  * See the LICENSE.txt file shipped along with this file for the license.
    7.  *
    8.  *************************************************************************/
    9.  
    10. #include <QtGui>
    11.  
    12. int main(int argc, char *argv[])
    13. {
    14. QApplication app(argc, argv);
    15.  
    16. QWidget window; // our top-level window
    17.  
    18. QLabel *itemLabel=new QLabel("Item",window);
    19. QLineEdit *lineEdit=new QLineEdit(window);
    20. QLabel *itemlistLabel=new QLabel("Item",window);
    21. QPushButton *addPushButton=new QPushButton("Add",window);
    22. QTextEdit *textEdit=new QTextEdit(window);
    23.  
    24. //widget layout
    25. QHBoxLayout *inner=new QHBoxLayout();
    26. inner->addWidget(itemLabel);
    27. inner->addWidget(lineEdit);
    28. inner->addWidget(addPushButton);
    29. QVBoxLayout *outer=new QVBoxLayout();
    30. outer->addWidget(inner);
    31. outer->addWidget(itemlistLabel);
    32. outer->addWidget(textEdit);
    33.  
    34. window.setLayout(outer);
    35.  
    36.  
    37. // ... your code here
    38.  
    39. window.resize(480, 640);
    40. window.show();
    41.  
    42. return app.exec();
    43. }
    To copy to clipboard, switch view to plain text mode 


    Added after 18 minutes:


    Yeah!I have done it using QtDesigner!

    But how can I achieve this without QtDesigner?

    Can you tell me how?

    I am confused.
    Attached Images Attached Images
    Last edited by dagobert1989; 13th January 2011 at 14:14.

  10. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QtTraining-Your First Qt Application

    Gentle I want remind all here, that we do not solve homeworks!

    Please tell us, what exactly does not work for you since we won't provide any code you can copy and paste. You might want have a look at the signals and slots mechanism of Qt.

  11. #8
    Join Date
    Jan 2011
    Location
    China->Nanjing
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtTraining-Your First Qt Application

    I am sorry!

  12. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QtTraining-Your First Qt Application

    Quote Originally Posted by dagobert1989 View Post
    I am sorry!
    There is nothing to be sorry about. Try only to ask a precise question. Only by looking at the picture I do not see if you have problems with the layout or with a functionality.

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

    dagobert1989 (13th January 2011)

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

    Default Re: QtTraining-Your First Qt Application

    Quote Originally Posted by dagobert1989 View Post
    Yeah!I have done it using QtDesigner!

    But how can I achieve this without QtDesigner?
    Well, QtDesigner generates the code for you, so to do it without QtDesigner, you write similar code to what QtDesigner produces....

    If you want the buttons to do something, then you need to research signals and slots, as already suggested.

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

    dagobert1989 (14th January 2011)

  16. #11
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QtTraining-Your First Qt Application

    The advice squidge gave you is very good.
    But that code also uses some technical stuff you don't need to use, since that file is meant to be auto-generated and you are not supposed to write code just like UIC and then integrate it with the rest of your project using one of these methods
    So basically that file includes some tricks that allows the Qt programmers to keep separated the auto-generated code from the code they write.

    So i would like to add that the advice squidge gave you is for those somehow advanced C++ programmers.
    If you are experienced with C++ you can easy understand that file, and you can get inspiration form there, don't forget that

    The recommended reading for those new to Qt layouts is this
    Also documentation for signals and slots

  17. #12
    Join Date
    Jan 2011
    Location
    China->Nanjing
    Posts
    5
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QtTraining-Your First Qt Application

    Quote Originally Posted by Zlatomir View Post
    The advice squidge gave you is very good.
    But that code also uses some technical stuff you don't need to use, since that file is meant to be auto-generated and you are not supposed to write code just like UIC and then integrate it with the rest of your project using one of these methods
    So basically that file includes some tricks that allows the Qt programmers to keep separated the auto-generated code from the code they write.

    So i would like to add that the advice squidge gave you is for those somehow advanced C++ programmers.
    If you are experienced with C++ you can easy understand that file, and you can get inspiration form there, don't forget that

    The recommended reading for those new to Qt layouts is this
    Also documentation for signals and slots
    Thanks a lot,you are very kind.
    I a newbie,so I don't know the signals and slots.
    I am trying to understand the signals and slots by reading the documentation.
    Thanks for your suggestsion.


    Added after 56 minutes:



    I did it!
    I achieve this UI without using QtDesigner!
    code here:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QWidget window; // our top-level window
    8. //your code here...
    9. QLabel *itemLabel=new QLabel("Item");
    10. QLineEdit *lineEdit=new QLineEdit();
    11. QLabel *itemlistLabel=new QLabel("ItemList");
    12. QPushButton *addPushButton=new QPushButton("Add");
    13. QTextEdit *textEdit=new QTextEdit();
    14.  
    15. //widget layout
    16. QHBoxLayout *inner=new QHBoxLayout();
    17. inner->addWidget(itemLabel);
    18. inner->addWidget(lineEdit);
    19. inner->addWidget(addPushButton);
    20. QVBoxLayout *outer=new QVBoxLayout();
    21. outer->addLayout(inner);
    22. outer->addWidget(itemlistLabel);
    23. outer->addWidget(textEdit);
    24.  
    25. window.setLayout(outer);
    26.  
    27.  
    28. // ... your code here
    29.  
    30. window.resize(480, 640);
    31. window.show();
    32.  
    33. return app.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 
    Thanks these kind people who helped me!
    Last edited by dagobert1989; 14th January 2011 at 07:42.

Similar Threads

  1. Replies: 8
    Last Post: 5th November 2012, 08:43
  2. Replies: 2
    Last Post: 21st November 2010, 18:03
  3. Replies: 3
    Last Post: 20th October 2010, 22:36
  4. Replies: 3
    Last Post: 6th January 2010, 16:55
  5. Replies: 12
    Last Post: 29th February 2008, 13:35

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
  •  
Qt is a trademark of The Qt Company.