December 8, 2010

Volker Volker
Ant Farmer
5428 posts

Getting started example is buggy

 

The second example in the Getting Started Programming with Qt [doc.qt.nokia.com] guide is buggy.

The wrong code is:

  1. #include <QtGui>
  2.  
  3. int main(int argv, char **args)
  4. {
  5.     QApplication app(argv, args);
  6.  
  7.     QTextEdit textEdit;
  8.     QPushButton quitButton("Quit");
  9.  
  10.     QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
  11.  
  12.     QVBoxLayout layout;
  13.     layout.addWidget(&textEdit);
  14.     layout.addWidget(&quitButton);
  15.  
  16.     QWidget window;
  17.     window.setLayout(&layout);
  18.  
  19.     window.show();
  20.  
  21.     return app.exec();
  22. }

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:

  1. #include <QtGui>
  2.  
  3. int main(int argv, char **args)
  4. {
  5.     QApplication app(argv, args);
  6.  
  7.     QWidget window;
  8.  
  9.     QTextEdit *textEdit = new QTextEdit(&window);
  10.     QPushButton *quitButton = new QPushButton("Beenden");
  11.  
  12.     QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
  13.  
  14.     QVBoxLayout layout;
  15.     layout.addWidget(textEdit);
  16.     layout.addWidget(quitButton);
  17.  
  18.     window.setLayout(&layout);
  19.  
  20.     window.show();
  21.  
  22.     return app.exec();
  23. }

Should we adapt the translated versions here in the wiki?

9 replies

December 8, 2010

paulo paulo
Ant Farmer
174 posts

I fix the spanish version [developer.qt.nokia.com]

December 8, 2010

xsacha xsacha
Lab Rat
517 posts

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.

 Signature 

- Sacha

December 8, 2010

QtK QtK
Lab Rat
1140 posts
xsacha wrote:
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.

That might be due to just translating the text and not the example applications. Might have used the same screen shots originally available.

December 8, 2010

xsacha xsacha
Lab Rat
517 posts

I know, don’t know if screenshots are intentional.
However, the code has translated text in the first instance “Salir”, but not the second instance “Quit”. This cannot be intentional.

And what about references to the text?

 Signature 

- Sacha

July 8, 2012

donallen donallen
Lab Rat
2 posts

@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

July 9, 2012

koahnig koahnig
Area 51 Engineer
2881 posts

donallen wrote:
@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


In the recent version 4.8 [qt-project.org] 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]

July 9, 2012

donallen donallen
Lab Rat
2 posts

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.

July 9, 2012

koahnig koahnig
Area 51 Engineer
2881 posts

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 [qt-project.org] 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.

July 9, 2012

koahnig koahnig
Area 51 Engineer
2881 posts

I have filed a bug report on JIRA. [bugreports.qt-project.org] Let’s see, if someone of the Trolls may do anything about it.

 
  ‹‹ [Suggestion] Mark pages to be renamed with standardized tag and to-do message      Poll: Drop CamelCase in the wiki titles? ››

You must log in to post a reply. Not a member yet? Register here!