Qt not being installed on win XP and question about QObject::connect() function.
-
I'm newbie here so sorry if I post it in wrong place. I know c++ but not visual. I used to make Qt style sheets and developed interest in programming. I have worked with Qt style sheets and I remember name of almost every function but my logical programming isn't good enough. My slow internet finally managed to download huge Qt SDK and I have two following problems.
First,
I tried installing Qt on my school PC which is as old as hills having window XP and 512 MB ram. I tried installing Qt thre but it said "Setup not configured properly" where it worked fine on my pc. I have win 7, 2 GB ram. Is there any way to install it there. We use code::block at school. Can I link Qt with code::block?Second,
I have problem with following code.
Here is what I wrote
@
#include <QtGui>int main(int argv, char **args)
{
QApplication app(argv, args);QTextEdit textEdit;
QPushButton but("Quit");QObject::connect(&but, SIGNAL(clicked()), app, SLOT(quit()));
QVBoxLayout lay;
lay.addWidget(&textEdit);
lay.addWidget(&but);QWidget win;
win.setLayout(&lay);
win.show();return app.exec();
}
@
It works fine when I copy paste from tutorial. But when I rewrote it myself, it didn't work. I tried many times but no solution.Here is original tutorial code from Qt documentation.
@
#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();
}
@I got this error
EDIT:
I replaced the code as guziemic said but still getting this error :(
H:\programs\Qt_Test-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Release..\Qt_Test\main.cpp:31: error: C2665: 'QObject::connect' : none of the 3 overloads could convert all the argument types
c:\QtSDK\Desktop\Qt\4.8.1\msvc2010\include\QtCore/qobject.h(204): could be 'bool QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)'
c:\QtSDK\Desktop\Qt\4.8.1\msvc2010\include\QtCore/qobject.h(217): or 'bool QObject::connect(const QObject *,const QMetaMethod &,const QObject *,const QMetaMethod &,Qt::ConnectionType)'
c:\QtSDK\Desktop\Qt\4.8.1\msvc2010\include\QtCore/qobject.h(231): or 'bool QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const'
while trying to match the argument list '(QPushButton *, const char [11], QApplication, const char [8])'Thank you.
-
Hi,
It is better if you put code with code markers '@' '@' then it is more readable.
Regarding error you did not define to which slot and signal you would like to connect. I assume that when you click on some button then application should be closed. Then code should look following
Should be:
@
QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit())));
@ -
Note the missing parenthesis in your connect call in the signal parameter.
Moderators note:
It is much more useful to ask separate questions in separate topics. It also allows to move the question to the right forum. Also, the Lounge forum where you posted is not meant for on-topic Qt support questions. It is more for general chat and meta-discussions. -
@QObject::connect(&quitButton, SIGNAL(clicked()), qApp, SLOT(quit())));@
Should probably be
@QObject::connect(&quitButton, SIGNAL(clicked()), app, SLOT(quit())));@
I am assuming you are wanting to refer QApplication Object which you have named as "app" but are calling it
"qApp" in your connect statement. Unless there is something I am missing. -
"qApp":http://qt-project.org/doc/qt-4.8/qapplication.html#qApp is a macro that give a pointer to the global QApplication instance. And as connnect() requires a pointer to a QObject, qApp works. Or you could take the address of your app variable:
@QObject::connect(&quitButton, SIGNAL(clicked()), &app, SLOT(quit()));@