Thanks fnmblot as well as Thanks again jpn .
It seems that I'm that kind of annoying students who won't stop questioning
I've made what you 've told me & separated the declaration from the implementation .
However , my slot didn't work yet ?!!
+ How does the header file which generated ,ui_Test.h , can call my CustomSlot ?!!
I've changed a little in my App :
Here are my Codes :
=> Main.cpp 's code is :
#include <QApplication>
#include <QDialog>
#include "ui_Test.h"
int main(int argc, char *argv[])
{
Ui_MyForm ui;
ui.setupUi(widget);
widget->show();
return app.exec();
}
#include <QApplication>
#include <QDialog>
#include "ui_Test.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *widget = new QWidget;
Ui_MyForm ui;
ui.setupUi(widget);
widget->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
---------------------------------------------------------------------------------------------------------------
ui_Test.h 's code is :
/********************************************************************************
** Form generated from reading ui file 'Test.ui'
**
** Created: Thu Jun 5 19:58:05 2008
** by: Qt User Interface Compiler version 4.4.0
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_TEST_H
#define UI_TEST_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MyForm
{
public:
{
if (MyForm->objectName().isEmpty())
MyForm
->setObjectName
(QString::fromUtf8("MyForm"));
MyForm->resize(533, 393);
btnCreateFile
->setObjectName
(QString::fromUtf8("btnCreateFile"));
btnCreateFile
->setGeometry
(QRect(170,
190,
75,
24));
txtData
->setObjectName
(QString::fromUtf8("txtData"));
txtData
->setGeometry
(QRect(160,
90,
113,
20));
retranslateUi(MyForm);
QObject::connect(btnCreateFile,
SIGNAL(pressed
()), MyForm,
SLOT(CreateFile
()));
} // setupUi
void retranslateUi
(QWidget *MyForm
) {
Q_UNUSED(MyForm);
} // retranslateUi
};
namespace Ui {
class MyForm: public Ui_MyForm {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_TEST_H
/********************************************************************************
** Form generated from reading ui file 'Test.ui'
**
** Created: Thu Jun 5 19:58:05 2008
** by: Qt User Interface Compiler version 4.4.0
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_TEST_H
#define UI_TEST_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MyForm
{
public:
QPushButton *btnCreateFile;
QLineEdit *txtData;
void setupUi(QWidget *MyForm)
{
if (MyForm->objectName().isEmpty())
MyForm->setObjectName(QString::fromUtf8("MyForm"));
MyForm->resize(533, 393);
btnCreateFile = new QPushButton(MyForm);
btnCreateFile->setObjectName(QString::fromUtf8("btnCreateFile"));
btnCreateFile->setGeometry(QRect(170, 190, 75, 24));
txtData = new QLineEdit(MyForm);
txtData->setObjectName(QString::fromUtf8("txtData"));
txtData->setGeometry(QRect(160, 90, 113, 20));
retranslateUi(MyForm);
QObject::connect(btnCreateFile, SIGNAL(pressed()), MyForm, SLOT(CreateFile()));
QMetaObject::connectSlotsByName(MyForm);
} // setupUi
void retranslateUi(QWidget *MyForm)
{
MyForm->setWindowTitle(QApplication::translate("MyForm", "Form", 0, QApplication::UnicodeUTF8));
btnCreateFile->setText(QApplication::translate("MyForm", "PushButton", 0, QApplication::UnicodeUTF8));
txtData->setText(QString());
Q_UNUSED(MyForm);
} // retranslateUi
};
namespace Ui {
class MyForm: public Ui_MyForm {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_TEST_H
To copy to clipboard, switch view to plain text mode
---------------------------------------------------------------------------------------------------------------
=> CustomSlot.h 's code is :
#ifndef CustmSlot_Declaration_H
#define CustmSlot_Declaration_H
#include "ui_Test.h"
{
Q_OBJECT
public:
private slots:
void CreateFile();
private:
Ui_MyForm ui;
};
#endif
#ifndef CustmSlot_Declaration_H
#define CustmSlot_Declaration_H
#include "ui_Test.h"
class CustomSlot: public QWidget
{
Q_OBJECT
public:
CustomSlot(QWidget *parent = 0);
private slots:
void CreateFile();
private:
Ui_MyForm ui;
};
#endif
To copy to clipboard, switch view to plain text mode
---------------------------------------------------------------------------------------------------------------
=> CustomSlot.cpp 's code is :
#include"CustomSlot.h"
#include "ui_Test.h"
#include <stdio.h>
CustomSlot
::CustomSlot(QWidget *parent
) {
ui.setupUi(this);
}
void CustomSlot:: CreateFile()
{
FILE * pFile;
pFile = fopen ("C:/myfile.txt","w");
}
#include"CustomSlot.h"
#include "ui_Test.h"
#include <stdio.h>
CustomSlot::CustomSlot(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
}
void CustomSlot:: CreateFile()
{
FILE * pFile;
pFile = fopen ("C:/myfile.txt","w");
}
To copy to clipboard, switch view to plain text mode
Thanks
Bookmarks