I am writing a simple program that displays an image when a button is pressed. I'm very new to Qt, and I am not having any luck identifying where my problem is occurring.
class ImageSwitcher : public QWidget
{
Q_OBJECT
public:
ImageSwitcher();
QPushButton *leftButton;
QPushButton *rightButton;
~ImageSwitcher();
private slots:
void switchImages(QPixmap display);
private:
QLabel *canvas;
QPixmap *one;
QPixmap *two;
};
class declaration:
ImageSwitcher::ImageSwitcher (void) {
canvas = new QLabel;
one = new QPixmap;
two = new QPixmap;
leftButton = new QPushButton("&One");
rightButton = new QPushButton("&Two");
one->load("one.png");
two->load("two.png");
//Close the program if the images cannot be loaded.
//Load the images to the QPixmaps.
//Connect the left and right buttons.
QObject::connect(leftButton, SIGNAL(clicked()), canvas, SLOT(switchImages(*one)));
QObject::connect(rightButton, SIGNAL(clicked()), canvas, SLOT(switchImages(*two)));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(canvas);
layout->addWidget(leftButton);
layout->addWidget(rightButton);
QWidget window;
window.setLayout(layout);
}
void ImageSwitcher::switchImages(QPixmap display) {
canvas->setPixmap(display);
}
ImageSwitcher::~ImageSwitcher (void) {
delete canvas;
delete one;
delete two;
delete leftButton;
delete rightButton;
}
and lastly the main function:
int main (int args, char **argv)
{
QApplication app(args, argv);
ImageSwitcher test;
test.show();
return app.exec();
}
The first problem I am having is that my layout is setup incorrectly. Secondly, the command line warns that switchImages() is not a SLOT for two. Oddly, it doesn't give me the same warning for one. None of the widgets populate when I run, so, I'm not really sure if the connections are working at all.
Any help is appreciated, thanks.