Private slots: quit(); not working
-
Hi,
I'm pretty new to QT4, so I'm trying to do this tutorial: http://doc.qt.nokia.com/latest/gettingstartedqt.html
It all goes well, untill the GUI is put in a class. Even though I could copy almost all code, I just can't get it to work. My code so far:
main.cpp:
@
#include <QtGui>
#include "notepad.h"int main(int argc, char *argv[])
{
QApplication app(argc, argv);Notepad window; window.show(); return app.exec();
}
@header:
@
#ifndef NOTEPAD_H
#define NOTEPAD_H#include <QtGui>
class Notepad : public QWidget
{
Q_OBJECTpublic:
Notepad();private slots:
void quit();private:
QTextEdit *textEdit;
QPushButton *quitButton;
};#endif // NOTEPAD_H
@notepad.cpp (just with constructor):
@
#include "notepad.h"// Constructor
Notepad::Notepad(){textEdit = new QTextEdit; quitButton = new QPushButton(tr("Quit")); connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(textEdit); layout->addWidget(quitButton); setLayout(layout); setWindowTitle(tr("Notepad"));
}
@The errors i get is:
moc_notepad.o:: In functionNotepad::qt_metacall(QMetaObject::Call, int, void**)': moc_notepad.cpp:72: error: undefined reference to
Notepad::quit()'
:: error: collect2: ld returned 1 exit statusCan someone please explain what I'm doing wrong? Thank you very much!!
edit:
fixed wrong link to tutorial -
Class QWidget does not have a slot quit. If you did not define one yourself (which is very likely) your subclass dosn't either. So the connect in line 9 of the cpp cannot succeed.
You probably want to connect to slot quit() of the global QApplication object (available via qApp) or do in the main function, before calling app.exec():
@
connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));
@ -
I'm sorry, I don't really understand what you mean. I tried adding that line of code to my main file but then it says 'connect' is not declared in this scope.
I made an error with copy/pasting the link to the tutorial, it must be this one:
http://doc.qt.nokia.com/latest/gettingstartedqt.html
About halfway the page it's being explained. I'm supposed to get a confirmation windows when pressing the quit button, but I don't see how that's implemented... -
Ah, I see. Unfortunately, the tutorial has some serious oddities.
Have a look at my forum post "Oddities in Getting Started Programming with Qt":http://developer.qt.nokia.com/forums/viewthread/1554 to see the missing methods and some other comments.
-
Ah, that's just great :( I guess it's better to just try another tutorial then... Can you recommend me a tutorial or website which teaches me the basics? It doesn't necessarily has to be an official one from Nokia, but it would be nice if it is complete and a working source code is available...
-
A tutorial is suppose to help people unfamiliar with something get up to some sort of speed with it.
Leaving out critical items from the tutorial is not helpful.I followed the link to find a solution to the same issue posted above and there was none.
So - there are at least two (2) people stuck with this tutorial. If I cannot get this to work, what hope is there using the QtCreator GUI?
Not everyone was born with an expert level of coding GUI interfaces.
-
I downloaded Qt a few days ago.
This is the tutorial I am following:
http://doc.qt.nokia.com/4.7/gettingstartedqt.html
Please provide me with a pointer to the fixed version. I'd like to get out of the hole that I'm in.
Thx!
-
bq. If I cannot get this to work, what hope is there using the QtCreator GUI?
A little melodramatic, don't you think?
Allow me a quick rant, please. There are plenty of tutorials and examples around. While not everyone was born with an expert level of coding GUI interfaces (none were, as far as I can tell) everyone who has ever become an expert was able to use the resources available to build their knowledge. If you're willing to give up all hope because one particular tutorial doesn't meet your standards, then I think that says more about your ambition than it does about the tutorial.
With that said, though, please do look around at the numerous other examples and tutorials that exist (a search on this site should point you to a number of them) and give it a try. If you have specific problems or questions, or if you get stuck somewhere, by all means post a message on the forums. There are tons of us on here who are more than happy to do our best to help you learn. That's what our community is all about. But you have to be constructive in your questions before we can be constructive in our answers.
We are here to help!
-
[quote author="lapin" date="1336599157"]This is the tutorial I am following:
http://doc.qt.nokia.com/4.7/gettingstartedqt.html
Please provide me with a pointer to the fixed version.[/quote]I'll give you a hint: The current Qt version is 4.8. Maybe you can figure out the link to the latest version yourself ;)