You are not logged in.

1

Saturday, June 21st 2008, 7:29pm

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):

#include <QStringList>
#include <QDebug>
#include <iostream>

using namespace std;

/* Some simple examples using QStringList, split and join */

int main() {
QString winter = "December, January, February";
QString spring = "March, April, May";
QString summer = "June, July, August";
QString fall = "September, October, November";

QStringList list;
list << winter;
list += spring;
list.append(summer);
list << fall;

qDebug() << "The Spring months are: " << list[1] ;
cout << "Hi" << endl;

QString allmonths = list.join(", ");
/* from list to string - join with a ", " delimiter */
qDebug() << allmonths;

QStringList list2 = allmonths.split(", ");
/* split is the opposite of join. Each month will have its own element. */

Q_ASSERT(list2.size() == 12);

foreach (QString str, list) {
qDebug() << QString(" [%1] ").arg(str);
}

for (QStringList::iterator it = list.begin();
it != list.end(); ++it) {
QString current = *it;
qDebug() << "[[" << current << "]]";
}

QListIterator<QString> itr (list2);
while (itr.hasNext()) {
QString current = itr.next();
qDebug() << "{" << current << "}";
}

return 0;
}


To create the executable I used the commands

qmake -project

qmake

make release



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.

charlse

Beginner

  • "charlse" is male

Posts: 4

Location: CHN

Occupation: Software Development

  • Send private message

2

Tuesday, July 8th 2008, 3:37am

Hi :

I do as your steps: the result is as followed . I don't know whether the result you wanted )

debian:/mnt/hgfs/share/Windows# ./Windows
The Spring months are: "March, April, May"
Hi
"December, January, February, March, April, May, June, July, August, September, October, November"
" [December, January, February] "
" [March, April, May] "
" [June, July, August] "
" [September, October, November] "
[[ "December, January, February" ]]
[[ "March, April, May" ]]
[[ "June, July, August" ]]
[[ "September, October, November" ]]
{ "December" }
{ "January" }
{ "February" }
{ "March" }
{ "April" }
{ "May" }
{ "June" }
{ "July" }
{ "August" }
{ "September" }
{ "October" }
{ "November" }


:)
有志者,事竟成!