I'm using Qt 4.6.3 SDK on the 64 bit version Fedora 13. I created a project via Creator & the form via Designer. It's a trivial program intended only to experiment with Signals & Slots to get me started with Qt. I've read everything I can find & I've done just what the docs say is right, but it doesn't work. I'm including the code from the header & cpp as well as the output from the build. Any help in understanding why this isn't working will be greatly appreciated.
Note: The app does run & the initial string is displayed.
Thanx,
Ed
This is the header:
#ifndef SANDSDEMO_H
#define SANDSDEMO_H
#include <QWidget>
#include <QObject>
#include <QLabel>
namespace Ui {
class SandSDemo;
}
{
Q_OBJECT
public:
explicit SandSDemo
(QWidget *parent
= 0);
~SandSDemo();
public slots:
void cancelText();
private:
Ui::SandSDemo *ui;
void initialText();
};
#endif // SANDSDEMO_H
#ifndef SANDSDEMO_H
#define SANDSDEMO_H
#include <QWidget>
#include <QObject>
#include <QLabel>
namespace Ui {
class SandSDemo;
}
class SandSDemo : public QWidget
{
Q_OBJECT
public:
explicit SandSDemo(QWidget *parent = 0);
~SandSDemo();
public slots:
void cancelText();
private:
Ui::SandSDemo *ui;
void initialText();
};
#endif // SANDSDEMO_H
To copy to clipboard, switch view to plain text mode
This is the source:
#include "sandsdemo.h"
#include "ui_sandsdemo.h"
SandSDemo
::SandSDemo(QWidget *parent
) : ui(new Ui::SandSDemo)
{
ui->setupUi(this);
connect(ui->cancelButton,SIGNAL(clicked()),ui->msgArea,SLOT(cancelText()));
initialText();
}
SandSDemo::~SandSDemo()
{
delete ui;
}
void SandSDemo::initialText()
{
QString * initialMsg
= new QString( "This is the string that will be displayed upon initialization.");
ui->msgArea->setText(*initialMsg);
delete initialMsg;
}
void SandSDemo::cancelText()
{
QString * cancelMsg
= new QString("This is the string that will be displayed when the cancel button is clicked.");
ui->msgArea->setText(*cancelMsg);
delete cancelMsg;
}
#include "sandsdemo.h"
#include "ui_sandsdemo.h"
SandSDemo::SandSDemo(QWidget *parent) :
QWidget(parent),
ui(new Ui::SandSDemo)
{
ui->setupUi(this);
connect(ui->cancelButton,SIGNAL(clicked()),ui->msgArea,SLOT(cancelText()));
initialText();
}
SandSDemo::~SandSDemo()
{
delete ui;
}
void SandSDemo::initialText()
{
QString * initialMsg = new QString( "This is the string that will be displayed upon initialization.");
ui->msgArea->setText(*initialMsg);
delete initialMsg;
}
void SandSDemo::cancelText()
{
QString * cancelMsg = new QString("This is the string that will be displayed when the cancel button is clicked.");
ui->msgArea->setText(*cancelMsg);
delete cancelMsg;
}
To copy to clipboard, switch view to plain text mode
This is the error from the build output:
Starting /home/ed/projects/SandSDemo-build-desktop/SandSDemo...
Object::connect: No such slot QLabel::cancelText() in ../SandSDemo/sandsdemo.cpp:9
Object::connect: (sender name: 'cancelButton')
Object::connect: (receiver name: 'msgArea')
/home/ed/projects/SandSDemo-build-desktop/SandSDemo exited with code 0
Bookmarks