Hi all,
I have read many tutorials on programming in KDE with QTDesigner. When I write small apps to learn, everything compiles and runs fine including any slots and signals I have. I wanted to learn a little more and understand more how slots and signals work so I decided to write a small learning app not using QTDeisgner and do it all manual.
My problem is I am writing an app with 2 buttons one with a Quit button and another with an Open button that calls a function openmyimage. From what I have been reading it looks like its fine but when I compile ( no warnings or errors ) and run the small learning app I keep getting a message in the Application tab in KDevelop:
QObject::connect: No such slot QApplication::openmyimage()
QObject::connect: (sender name: 'openbutton')
QObject::connect: (receiver name: 'chtest')
Then the application shows with two buttons.
This causes the Open button to do nothing when clicked. Right now all I wanted to do in the openmyimage function is to call a qwarning to display a message in the Application tab.
I need another pair of eyes to pinpoint my mistake. Can anyone please take a look at my code and let me know where I went wrong. Since this is just a learning app for me to learn Signals and Slots a little better I did everything in one file and compiled so copying this code and pasting it in your dev environment should work.
Code:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <qapplication.h>
#include <qfont.h>
#include <qpushbutton.h>
class MyWidget : public QWidget
{
//Q_OBJECT
public:
MyWidget(QWidget *parent=0, const char *name=0);
public slots:
void openmyimage();
signals:
void clicked();
};
MyWidget::MyWidget (QWidget *parent, const char *name) : QWidget(parent, name)
{
setMinimumSize (200,120);
setMaximumSize (200,120);
QPushButton *quit = new QPushButton("Quit", this, "quit");
quit->setGeometry(10,10,75,30);
quit->setFont( QFont("Times", 18, QFont::Bold));
QPushButton *btnopen = new QPushButton("Open1", this, "openbutton");
btnopen->setGeometry(10,45,75,30);
btnopen->setFont( QFont("Times", 18, QFont::Bold));
connect (quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
connect (btnopen, SIGNAL(clicked()), qApp, SLOT(openmyimage()) );
qWarning("Finished in Constructor");
}
void MyWidget::openmyimage()
{
qWarning("test");
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWidget w;
w.setGeometry (100,100,200,120);
a.setMainWidget( &w);
w.show();
return a.exec();
}
I have alrady tried moving each class into its own .cpp and .h file with the same results. Changed the slot name,
Changed
Code:
connect (btnopen, SIGNAL(clicked()), qApp, SLOT(openmyimage()) );
to
Code:
connect (btnopen, SIGNAL(clicked()), this, SLOT(openmyimage()) );
When I add Q_OBJECT into the MyWidget class I get a compile error with just an exit status 2.
Thanks for taking the time to look.
Gnarg