I really appreciate your comments and help. Also for the langauge, I am really sorry! I will make sure in the future that english is used.
Concerning my problem, I have revised deeply the code following your recommendations and I have make it clearer. Until now, I can't have any window after compilation. I received the following message: "The program ended abruptly".
I would be greatfull to any of you if you help me solving this problem.
Below is the new code with more modifications:
MainWindow.h:
#ifndef DEF_MAINWINDOW
#define DEF_MAINWINDOW
#include <QtGui>
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
protected slots:
void openFile();
void saveFile();
void codage();
void openChildWindow();
private:
};
#endif
#ifndef DEF_MAINWINDOW
#define DEF_MAINWINDOW
#include <QtGui>
class MainWindow: public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
protected slots:
void openFile();
void saveFile();
void codage();
void openChildWindow();
private:
QWidget *m_MainWindow;
QPushButton *m_Exit;
QRadioButton *m_codage;
QLineEdit *m_openFile, *m_saveFile;
};
#endif
To copy to clipboard, switch view to plain text mode
ChildWindow.h:
#ifndef DEF_CHILDWINDOW
#define DEF_CHILDWINDOW
#include<QtGui>
{
Q_OBJECT
public:
~ChildWindow();
private:
};
#endif // CHILDWINDOW_H
#ifndef DEF_CHILDWINDOW
#define DEF_CHILDWINDOW
#include<QtGui>
class ChildWindow: public QMainWindow
{
Q_OBJECT
public:
ChildWindow(QWidget *parent);
~ChildWindow();
private:
QPushButton m_exitChildWindow, *m_seqPur;
};
#endif // CHILDWINDOW_H
To copy to clipboard, switch view to plain text mode
MainWindow.cpp:
#include "MainWindow.h"
#include "ChildWindow.h"
MainWindow::MainWindow()
{
this->setFixedSize(500, 230);
m_exit = new QpsuButton("Exit", this);
m_codage->move(50,120);
setCentralWidget(this);
connect(m_exit, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(m_openFile, SIGNAL(clicked()), this, SLOT(openFile()));
connect(m_saveFile, SIGNAL(clicked()), this, SLOT(saveFile()));
connect(m_codage, SIGNAL(clicked()), this, SLOT(codage()));
}
void MainWindow::openFile()
{
m_openFile->setText(file);
}
void MainWindow::saveFile()
{
m_saveFile->setText(file);
}
void MainWindow::codage()
{
QFile file1
("myText1.txt");
QFile file2
("myText2.txt); QString line;
if(!file1.open(QIODevice::ReadOnly))
{
QMessageBox::critical(this, "Warning", "Open a file please");
return;
}
file2.open(QIODevice::WriteOnly);
QTextStream out(&file2);
line = line.remove(1, 5);
out<< line<<"\r\n\r\n";
}
void MainWindow::openChildWindow()
{
ChildWindow *fene = new ChildWindow(this);
fene->show();
}
MainWindow::~MainWindow()
#include "MainWindow.h"
#include "ChildWindow.h"
MainWindow::MainWindow()
{
this->setFixedSize(500, 230);
m_exit = new QpsuButton("Exit", this);
m_codage = new QRadioButton(this);
m_codage->move(50,120);
setCentralWidget(this);
connect(m_exit, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(m_openFile, SIGNAL(clicked()), this, SLOT(openFile()));
connect(m_saveFile, SIGNAL(clicked()), this, SLOT(saveFile()));
connect(m_codage, SIGNAL(clicked()), this, SLOT(codage()));
}
void MainWindow::openFile()
{
QString file = QFileDialog::getOpenFileName(this, "Information", "Open", "*.text");
m_openFile->setText(file);
}
void MainWindow::saveFile()
{
QString file = QFileDialog::getSaveFileName(this, "Information", "Save");
m_saveFile->setText(file);
}
void MainWindow::codage()
{
QFile file1("myText1.txt");
QFile file2("myText2.txt);
QString line;
if(!file1.open(QIODevice::ReadOnly))
{
QMessageBox::critical(this, "Warning", "Open a file please");
return;
}
file2.open(QIODevice::WriteOnly);
QTextStream out(&file2);
line = line.remove(1, 5);
out<< line<<"\r\n\r\n";
}
void MainWindow::openChildWindow()
{
ChildWindow *fene = new ChildWindow(this);
fene->show();
}
MainWindow::~MainWindow()
To copy to clipboard, switch view to plain text mode
ChildWindow.cpp:
#include "Fenetre1.h"
{
m_exitChildWindow->move(200, 220);
m_seqPur->move(175, 220);
resize(475, 250);
connect(m_seqPur, SIGNAL(clicked()), this , SLOT(openChildWindow()));
connect(m_exitChildWindow, SIGNAL(clicked()), this, SLOT(close()));
}
ChildWindow::~ChildWindow()
{}
#include "Fenetre1.h"
ChildWindow::ChildWindow(QWidget *parent = 0): QMainWindow(parent)
{
m_exitChildWindow = new QPushButton("Exit", this);
m_exitChildWindow->move(200, 220);
m_seqPur = new QPushButton;
m_seqPur->move(175, 220);
resize(475, 250);
connect(m_seqPur, SIGNAL(clicked()), this , SLOT(openChildWindow()));
connect(m_exitChildWindow, SIGNAL(clicked()), this, SLOT(close()));
}
ChildWindow::~ChildWindow()
{}
To copy to clipboard, switch view to plain text mode
Main.cpp:
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char *argv[])
{
MainWindow fenPr;
fenPr.show();
return app.exec();
}
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow fenPr;
fenPr.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Many thanks in advance!
Bookmarks