Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error's including a Read Function in mainwindow
Forum Updated to NodeBB v4.3 + New Features

Error's including a Read Function in mainwindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 2.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by RIVOPICO
    #1

    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!

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Your function's signatures in its declaration and definition don't match:

      public slots:
          void Read();
      
      void MainWindow::Read(QString Filename)
      {
      
      RIVOPICOR 1 Reply Last reply
      3
      • ? A Former User

        Your function's signatures in its declaration and definition don't match:

        public slots:
            void Read();
        
        void MainWindow::Read(QString Filename)
        {
        
        RIVOPICOR Offline
        RIVOPICOR Offline
        RIVOPICO
        wrote on last edited by RIVOPICO
        #3

        @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.

        jsulmJ 1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          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 ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          4
          • RIVOPICOR RIVOPICO

            @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.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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)
            {...}
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved