Getting started example is buggy
-
The second example in the "Getting Started Programming with Qt":http://doc.qt.nokia.com/4.7/gettingstartedqt.html guide is buggy.
The wrong code is:
@
#include <QtGui>int main(int argv, char **args)
{
QApplication app(argv, args);QTextEdit textEdit; QPushButton quitButton("Quit"); QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); QVBoxLayout layout; layout.addWidget(&textEdit); layout.addWidget(&quitButton); QWidget window; window.setLayout(&layout); window.show(); return app.exec();
}
@The program segfaults on quitting. I suspect, that it is due to double deconstruction of textEdit and quitButton on program exit. They are constructed on the stack, and therefore destructed because they're going out of scope. Unfortunately they are deconstructed a second time, when window is destroyed, due to the fact that they are reparented to window, as soon as the layout is set.
I've reworked it, so that it works now and is more "Qt'ish", using pointers for child widgets:
@
#include <QtGui>int main(int argv, char **args)
{
QApplication app(argv, args);QWidget window; QTextEdit *textEdit = new QTextEdit(&window); QPushButton *quitButton = new QPushButton("Beenden"); QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); QVBoxLayout layout; layout.addWidget(textEdit); layout.addWidget(quitButton); window.setLayout(&layout); window.show(); return app.exec();
}
@Should we adapt the translated versions here in the wiki?
-
I fix the "spanish version":http://developer.qt.nokia.com/wiki/GettingStartedQt_Spanish
-
Just a small note since I guess everyone will be fixing up their wikis:
paulo: You seem to have translated the text on the QPushButton in the wiki code to "Salir". Yet the following screenshots and tutorial refer to it as "Quit".
Further on in the code of the tutorial, the QPushButton instead has the text "Quit" as well. -
[quote author="xsacha" date="1291774911"]Just a small note since I guess everyone will be fixing up their wikis:
paulo: You seem to have translated the text on the QPushButton in the wiki code to "Salir". Yet the following screenshots and tutorial refer to it as "Quit".
Further on in the code of the tutorial, the QPushButton instead has the text "Quit" as well.[/quote]That might be due to just translating the text and not the example applications. Might have used the same screen shots originally available.
-
[quote author="donallen" date="1341778891"]@Volker:
You posted your message year and a half ago, and the Getting Started manual still has this bug, to give others like me a chance to waste their time on it. Good work!
/Don Allen[/quote]
In the recent "version 4.8":http://qt-project.org/doc/qt-4.8/gettingstartedqt.html the doc bug is fixed. It even has Volker's note at the bottom.Which version of the documentation did you use?
[edit, typo corrected]
-
If you start at qt.nokia.com, which you find if you google for 'qt'. If you click 'Learn Qt', then 'Getting Started Guides', and then 'Getting Started Programming with Qt', you end up at
http://doc.qt.nokia.com/4.7/gettingstartedqt.html
which still has the bug.
So apparently the error was fixed in the 4.8 documentation, but the website takes you by default to the 4.7 version. Perhaps this isn't Volker's fault and if not, I apologize to him for my snotty message. But this is somebody's screwup, because the path I followed is the path a Qt novice, which I am, will follow, starting with the qt home page. If you follow your nose, starting with the qt home page, you end up at documentation for an old release.
-
IMO it is certainly not Volker's fault. You ran into a serious of mischief. At the devnet version of doc 4.7 "http://qt-project.org/doc/qt-4.7/gettingstartedqt.html":http://qt-project.org/doc/qt-4.7/gettingstartedqt.html has Volker's note at the bottom. I believe the version you have been trapped is has been migrated to devnet. If you just change the version number on your link it will automatically go to the devnet version.
Finally, the problem is Google's memory and probably the interest in Qt's documentation. It may take some time to change priorities there. I have noted also in the past that Google points to the older version 4.7 and reported it. Most likely nobody from Qt devnet can do anything about Google's list.
-
I have filed a "bug report on JIRA.":https://bugreports.qt-project.org/browse/QTWEBSITE-455 Let's see, if someone of the Trolls may do anything about it.