Results 1 to 4 of 4

Thread: Getting started with Qt

  1. #1

    Default Getting started with Qt

    I am just starting with Qt (open source) and I am going through examples in An Introduction to Design Patterns in C++ with Qt 4. My C++ experience is with console applications, and I would like to learn about gui programming.

    My problem is with the following example, slightly modified from the book (example 4.1):

    Qt Code:
    1. #include <QStringList>
    2. #include <QDebug>
    3. #include <iostream>
    4.  
    5. using namespace std;
    6.  
    7. /* Some simple examples using QStringList, split and join */
    8.  
    9. int main() {
    10. QString winter = "December, January, February";
    11. QString spring = "March, April, May";
    12. QString summer = "June, July, August";
    13. QString fall = "September, October, November";
    14.  
    15. list << winter;
    16. list += spring;
    17. list.append(summer);
    18. list << fall;
    19.  
    20. qDebug() << "The Spring months are: " << list[1] ;
    21. cout << "Hi" << endl;
    22.  
    23. QString allmonths = list.join(", ");
    24. /* from list to string - join with a ", " delimiter */
    25. qDebug() << allmonths;
    26.  
    27. QStringList list2 = allmonths.split(", ");
    28. /* split is the opposite of join. Each month will have its own element. */
    29.  
    30. Q_ASSERT(list2.size() == 12);
    31.  
    32. foreach (QString str, list) {
    33. qDebug() << QString(" [%1] ").arg(str);
    34. }
    35.  
    36. for (QStringList::iterator it = list.begin();
    37. it != list.end(); ++it) {
    38. QString current = *it;
    39. qDebug() << "[[" << current << "]]";
    40. }
    41.  
    42. QListIterator<QString> itr (list2);
    43. while (itr.hasNext()) {
    44. QString current = itr.next();
    45. qDebug() << "{" << current << "}";
    46. }
    47.  
    48. return 0;
    49. }
    To copy to clipboard, switch view to plain text mode 

    To create the executable I used the commands

    Qt Code:
    1. qmake -project
    2.  
    3. qmake
    4.  
    5. make release
    To copy to clipboard, switch view to plain text mode 



    I was expecting console output, but nothing happens when I run the executable. Neither the original example or my modified version seem to work. I suspect there is something I don't understand. So far the earlier book examples have worked.

    I realise this is a very basic question. If this is not the right forum, please let me know.
    Last edited by jpn; 25th June 2008 at 15:51. Reason: missing [code] tags

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting started with Qt

    Give us your .pro file.
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting started with Qt

    Are you on MS Windows?

    If Yes you have to write this in your .pro file
    Qt Code:
    1. CONFIG += console
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  4. #4

    Default Re: Getting started with Qt

    The console spec must be it. I know that it is not in my project file. It will try it when I get home tonight. Thanks.

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Getting Started
    By Hockey in forum Newbie
    Replies: 9
    Last Post: 29th November 2007, 21:43
  3. Replies: 2
    Last Post: 30th March 2007, 08:10
  4. How do I get started?
    By neigaard in forum Newbie
    Replies: 2
    Last Post: 12th March 2007, 08:42
  5. Replies: 10
    Last Post: 7th April 2006, 18:23

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.