Reputation: 386
Hi Im try to make a custom slot with the h file that qt4 designer generated I see how the standard slot is made but i would like to, "once past learning this step" have run terminal commands and have it output in the text box so im tryin to replace the past() slot with one i can right commands in Here is the h file file that works great but.... the above problem'' trying to understand the flow.. 2nd day so any pointers are awsome. so here it is i will comment where i think i should be working.. but have had no success all day lol.
#ifndef SWEETGUIFORMQ19488_H
#define SWEETGUIFORMQ19488_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QHeaderView>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_SweetGuiForm
{
public:
QVBoxLayout *verticalLayout_2;
QVBoxLayout *verticalLayout;
QTextEdit *textEdit;
QDialogButtonBox *buttonBox;
void setupUi(QWidget *SweetGuiForm)
{
if (SweetGuiForm->objectName().isEmpty())
SweetGuiForm->setObjectName(QString::fromUtf8("SweetGuiForm"));
SweetGuiForm->resize(511, 275);
verticalLayout_2 = new QVBoxLayout(SweetGuiForm);
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
verticalLayout = new QVBoxLayout();
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
textEdit = new QTextEdit(SweetGuiForm);
textEdit->setObjectName(QString::fromUtf8("textEdit"));
verticalLayout->addWidget(textEdit);
buttonBox = new QDialogButtonBox(SweetGuiForm);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
verticalLayout->addWidget(buttonBox);
verticalLayout_2->addLayout(verticalLayout);
QWidget::setTabOrder(textEdit, buttonBox);
retranslateUi(SweetGuiForm);
QObject::connect(buttonBox, SIGNAL(rejected()), SweetGuiForm, SLOT(close()));
ok here i guess i could replace the paste() with on_buttonBox_accepted(), please correct me i really am still quessing at this point but where do i right the function? do i do the in a file called sweetguiform.cpp ? this is where im lost.. help.. QObject::connect(buttonBox, SIGNAL(accepted()), textEdit, SLOT(paste()));
QMetaObject::connectSlotsByName(SweetGuiForm);
} // setupUi
void retranslateUi(QWidget *SweetGuiForm)
{
SweetGuiForm->setWindowTitle(QApplication::translate("SweetGuiForm", "Form", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class SweetGuiForm: public Ui_SweetGuiForm {};
} // namespace Ui
QT_END_NAMESPACE
#endif // SWEETGUIFORMQ19488_H
Is this the way to do things when brand new?
Upvotes: 0
Views: 58
Reputation: 1018
I think you shouldn't be editing the header file that Qt generates for you. Instead, you should write your own header/implementation file that includes this auto-generated header and sets up the signal-slot connections there. For example:
#include "ui_SweetGuiForm.h"
class SweetGuiForm : public QWidget
{
public:
SweetGuiForm( ): ui( new Ui::SweetGuiForm )
{
ui->setupUi( this );
}
public slots:
void on_buttonBox_accepted( )
{
// your code here
}
protected:
Ui::SweetGuiForm* ui;
};
Qt will find the on_buttonBox_accepted
method and set up the signal-slot connection for you, so you don't have to call QObject::connect
.
Upvotes: 1