Unsolved Error's including a Read Function in mainwindow
-
Hello i'm including a Read Function to read my resource file but when i do this the function is not recognized.
My file.pro:QT += core gui QT += testlib greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = untitled2 TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h \ resource.h FORMS += mainwindow.ui RESOURCES += \ myfiles.qrc
mainwindow.cpp:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <iostream> #include <QProcess> #include <QtTest> #include <QString> #include <QStringList> using namespace std; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); Read(":/MyFiles/MyAlias"); } MainWindow::~MainWindow() { delete ui; } void MainWindow::Read(QString Filename) { QFile mFile(Filename); if(!mFile.open(QFile::ReadOnly | QFile::Text)) { qDebug() << "could not open file for reading"; return; } QTextStream in(&mFile); QString mText = in.readAll(); qDebug() << mText; mFile.close(); }
mainwindow.h:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); public slots: void Read(); private: Ui::MainWindow *ui; }; #endif // MAINWINDOW_H
The errors i get:
error: no matching function for call to 'MainWindow::Read(const char [16])' Read(":/MyFiles/MyAlias"); ^ mainwindow.cpp:42: error: prototype for 'void MainWindow::Read(QString)' does not match any in class 'MainWindow' void MainWindow::Read(QString Filename) ^ mainwindow.h:19: error: candidate is: void MainWindow::Read() void Read(); ^
Thanks again!
-
Your function's signatures in its declaration and definition don't match:
public slots: void Read();
void MainWindow::Read(QString Filename) {
-
@Wieland said in Error's including a Read Function in mainwindow:
void MainWindow::Read(QString Filename)
{i did that but not seems to work.
what does it mean this errors?In file included from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/QtCore:13:0, from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtTest/QtTestDepends:3, from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtTest/QtTest:3, from ..\untitled2\mainwindow.cpp:6: C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qendian.h:53:0: warning: "QT_HAS_BUILTIN" redefined # define QT_HAS_BUILTIN(x) __has_builtin(x) ^ In file included from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qglobal.h:83:0, from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtGui/qwindowdefs.h:43, from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qwidget.h:43, from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qmainwindow.h:43, from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/QMainWindow:1, from ..\untitled2\mainwindow.h:4, from ..\untitled2\mainwindow.cpp:1: C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qcompilerdetection.h:1209:0: note: this is the location of the previous definition # define QT_HAS_BUILTIN(x) 0 ^ ..\untitled2\mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)': ..\untitled2\mainwindow.cpp:31:27: error: no matching function for call to 'MainWindow::Read(const char [16])' Read(":/MyFiles/MyAlias"); ^ In file included from ..\untitled2\mainwindow.cpp:1:0: ..\untitled2\mainwindow.h:19:10: note: candidate: void MainWindow::Read() void Read(); ^ ..\untitled2\mainwindow.h:19:10: note: candidate expects 0 arguments, 1 provided ..\untitled2\mainwindow.cpp:27:12: warning: unused variable 'lpc' [-Wunused-variable] LPCSTR lpc = cadena.c_str(); ^ ..\untitled2\mainwindow.cpp: At global scope: ..\untitled2\mainwindow.cpp:42:6: error: prototype for 'void MainWindow::Read(QString)' does not match any in class 'MainWindow' void MainWindow::Read(QString Filename) ^ In file included from ..\untitled2\mainwindow.cpp:1:0: ..\untitled2\mainwindow.h:19:10: error: candidate is: void MainWindow::Read() void Read(); ^
Now show me:
mainwindow.cpp:31: error: C2660: 'MainWindow::Reading' : the function doesnt accept 1 argument
But i specified one argument i dont know why this message.
-
Looks like some syntax issue you are hitting. Can you paste reading() function signature? Also how r you calling that function ? Better you paste your complete code ?
-
@RIVOPICO What is "MainWindow::Reading"? Wasn't the name of the method "MainWindow::Read" before?
This is really basic:// In header file public slots: void Read(QString); // in cpp file void MainWindow::Read(QString Filename) {...}