I am trying to build a Qt app provided as an example by Qt Creator.
Code:
arrowpad.h
:
#ifndef ARROWPAD_H
#define ARROWPAD_H
#include <QWidget>
QT_BEGIN_NAMESPACE
class QPushButton;
QT_END_NAMESPACE
//! [0]
class ArrowPad : public QWidget
//! [0] //! [1]
{
//! [1] //! [2]
Q_OBJECT
//! [2]
public:
ArrowPad(QWidget *parent = 0);
private:
QPushButton *upButton;
QPushButton *downButton;
QPushButton *leftButton;
QPushButton *rightButton;
};
#endif
arrowpad.cpp
:
#include <QtGui>
#include "arrowpad.h"
ArrowPad::ArrowPad(QWidget *parent)
: QWidget(parent)
{
//! [0]
upButton = new QPushButton(tr("&Up"));
//! [0] //! [1]
downButton = new QPushButton(tr("&Down"));
//! [1] //! [2]
leftButton = new QPushButton(tr("&Left"));
//! [2] //! [3]
rightButton = new QPushButton(tr("&Right"));
//! [3]
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(upButton, 0, 1);
mainLayout->addWidget(leftButton, 1, 0);
mainLayout->addWidget(rightButton, 1, 2);
mainLayout->addWidget(downButton, 2, 1);
setLayout(mainLayout);
}
How can I get it to run a command when I press a button?
I have found this : How to run a system command in Qt?.
But I don't know how to use it with QPushButton
, it just thinks it is a string of text.
Any commands must work in Linux Fedora 19, as that is what I am running it on.
Here's the current result, where I do not think the button names are specified as (tr("&Up"));
in the above .cpp
script by the way.