here is what i have, just doing some test to get familiar with QT Creator. This compiles but when I click one of the buttons the clicked signal does not trigger. Any Ideas?
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QtGui>
#include <QGridLayout>
#include <QSignalMapper>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
signals:
protected:
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QtGui>
#include <QGridLayout>
#include <QSignalMapper>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
signals:
void clicked(const QString &text);
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
QPushButton *theButton;
QGridLayout *theLayout;
QSignalMapper *theMapper;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
int count = 0;
for (int t = 0; t < 10 ; t++)
{
count++;
buttonName.setNum(count);
buttonName.prepend("Sequence");
theLayout->addWidget(theButton,count,1,1,1);
connect(theButton, SIGNAL(clicked()), theMapper, SLOT(map()));
theMapper->setMapping(theButton,buttonName);
}
centralWidget()->setLayout(theLayout);
connect(theMapper,
SIGNAL(mapped
(const QString &)),
this,
SIGNAL(clicked
(const QString &)));
}
{
qDebug() << text;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
theMapper = new QSignalMapper(this);
QGridLayout *theLayout = new QGridLayout();
int count = 0;
for (int t = 0; t < 10 ; t++)
{
count++;
QString buttonName;
buttonName.setNum(count);
buttonName.prepend("Sequence");
QPushButton *theButton = new QPushButton(buttonName);
theLayout->addWidget(theButton,count,1,1,1);
connect(theButton, SIGNAL(clicked()), theMapper, SLOT(map()));
theMapper->setMapping(theButton,buttonName);
}
centralWidget()->setLayout(theLayout);
connect(theMapper,SIGNAL(mapped(const QString &)),this,SIGNAL(clicked(const QString &)));
}
void clicked(const QString &text)
{
qDebug() << text;
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks