Hi Reddy!
It is difficult and complicate, since in QFile file1(m_openFile->text()), I am showing the path to the file to be used. In the decalration of the function, we have QString fileName, which will not be used in this case. Moreover, when I am testing if the file can be opened (if(!file1.open(QIODevice::ReadOnly)), with the return after the line of QMessageBox, I have the following error: "error : return-statement with no value, in function returning 'QStringList'"
Questions:
1- How to indicated the path to the file to be used in the declaration of the function in the heather file?
2- How to overcome the problem leading to the error message?
3- How to sole the entire problem?
Many thanks!
I have the following modified code:
first class.h
#ifndef DEF_HERITAGE
#define DEF_HERITAGE
#include <QtGui>
{
Q_OBJECT
public:
explicit Heritage
(QWidget *parent
= 0);
virtual ~Heritage();
public slots:
private:
};
#ifndef DEF_HERITAGE
#define DEF_HERITAGE
#include <QtGui>
class Heritage: public QMainWindow
{
Q_OBJECT
public:
explicit Heritage(QWidget *parent = 0);
virtual ~Heritage();
public slots:
QStringList operation1(QString fileName);
private:
QLineEdit *m_openFile;
};
To copy to clipboard, switch view to plain text mode
First class.cpp
#include "Heritage.h"
#include "ChildWindow.h"
Heritage
::Heritage(QWidget *parent
) {
setWindowTitle("Heritage");
setCentralWidget(centralWidget);
}
{
QFile file1
(m_openFile
->text
());
{
QMessageBox::critical(m_openFile,
"Warning",
"Open a file please");
return;
}
....
return list;
}
#include "Heritage.h"
#include "ChildWindow.h"
Heritage::Heritage(QWidget *parent)
{
m_openFile = new QLineEdit;
setWindowTitle("Heritage");
setCentralWidget(centralWidget);
}
QStringList Heritage::operation1(QString fileName)
{
QFile file1(m_openFile->text());
QStringList list;
if(!file1.open(QIODevice::ReadOnly))
{
QMessageBox::critical(m_openFile, "Warning", "Open a file please");
return;
}
....
return list;
}
To copy to clipboard, switch view to plain text mode
Second class.h
#ifndef DEF_CHILDWINDOW
#define DEF_CHILDWINDOW
#include<QtGui>
#include"Heritage"
{
Q_OBJECT
public:
explicit ChildWindow
(QWidget *parent
= 0);
virtual ~ChildWindow();
public slots:
private:
};
#endif // CHILDWINDOW_H
#ifndef DEF_CHILDWINDOW
#define DEF_CHILDWINDOW
#include<QtGui>
#include"Heritage"
class ChildWindow: public QWidget
{
Q_OBJECT
public:
explicit ChildWindow(QWidget *parent = 0);
virtual ~ChildWindow();
public slots:
void operation2(Heritage &aFile, QStringList &list);
private:
};
#endif // CHILDWINDOW_H
To copy to clipboard, switch view to plain text mode
Second class.cpp
#include "ChildWindow.h"
#include "Heritage.h"
ChildWindow
::ChildWindow(QWidget *parent
) {
}
void ChildWindow
::operation2(Heritage
&aFile,
QStringList &list
) {
list = aFile.operation1(m_openFile->text());
}
ChildWindow::~ChildWindow()
{
;
}
#include "ChildWindow.h"
#include "Heritage.h"
ChildWindow::ChildWindow(QWidget *parent)
: QWidget(parent)
{
}
void ChildWindow::operation2(Heritage &aFile, QStringList &list)
{
list = aFile.operation1(m_openFile->text());
}
ChildWindow::~ChildWindow()
{
;
}
To copy to clipboard, switch view to plain text mode
Bookmarks