spainchaud
25th June 2008, 07:01
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.
I realise this is a very basic question. If this is not the right forum, please let me know.
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.
I realise this is a very basic question. If this is not the right forum, please let me know.