Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QFile fails to include its own QtCore libraries in Qwt examples
Forum Update on Monday, May 27th 2025

QFile fails to include its own QtCore libraries in Qwt examples

Scheduled Pinned Locked Moved 3rd Party Software
7 Posts 3 Posters 4.4k Views
  • 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.
  • T Offline
    T Offline
    Tay2510
    wrote on last edited by
    #1

    Hi, I am using:

    • Qt 4.8.5 for MSVC 2010, Qt creator, and Windows 7 SDK debugger

    I've download Qwt and modify the example "oscilloscope."Now I am trying to add a functionality of writing file into disk with library.

    I got lots of compiler errors (like 90+, or sometimes 300+) when I had added this new file output functionality to my code, and all the errors pointed to the QFile library. It seems that the QFile.h fails to include "QtCore/qiodevice.h" and "QtCore/qstring.h".

    The following is a piece of code from library, and I pinpoint some compiler errors in it:

    @#ifndef QFILE_H
    #define QFILE_H

    #include <QtCore/qiodevice.h>
    #include <QtCore/qstring.h>
    #include <stdio.h>
    #ifdef Q_OS_SYMBIAN
    #include <f32file.h>
    #endif

    #ifdef open
    #error qfile.h must be included before any header file that defines open
    #endif

    QT_BEGIN_HEADER

    QT_BEGIN_NAMESPACE

    QT_MODULE(Core)

    class QAbstractFileEngine;
    class QFilePrivate;

    class Q_CORE_EXPORT QFile : public QIODevice
    {
    #ifndef QT_NO_QOBJECT
    Q_OBJECT
    #endif
    Q_DECLARE_PRIVATE(QFile)

    public:

    enum FileError {
        NoError = 0,    // C2059 syntax error:'constant'
        ReadError = 1,
        WriteError = 2,
        FatalError = 3,
        ResourceError = 4,
        OpenError = 5,
        AbortError = 6,
        TimeOutError = 7,
        UnspecifiedError = 8,
        RemoveError = 9,
        RenameError = 10,
        PositionError = 11,
        ResizeError = 12,
        PermissionsError = 13,
        CopyError = 14
    

    #ifdef QT3_SUPPORT
    , ConnectError = 30
    #endif
    }; // C2143 syntax error: missing ';'
    // C2238 c2238 unexpected token(s) preceding ';'

    enum Permission {
        ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
        ReadUser  = 0x0400, WriteUser  = 0x0200, ExeUser  = 0x0100,
        ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
        ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
    };
    Q_DECLARE_FLAGS(Permissions, Permission)
    
    enum FileHandleFlag {
        AutoCloseHandle = 0x0001,
        DontCloseHandle = 0
    };
    Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
    
    QFile&#40;&#41;;    // C2059 syntax error: '&#41;'
    QFile&#40;const QString &name&#41;;    // C2226 syntax error: unexpected type 'QString'
    

    #ifndef QT_NO_QOBJECT
    explicit QFile(QObject *parent); // C2143 syntax error: missing ')'
    // C2259 'QFile': cannot instantiate abstract class
    // C2071 'QObject': illegal storage class
    // C4430 missing type specifier
    // ... and more

    QFile&#40;const QString &name, QObject *parent&#41;;
    

    #endif
    ~QFile();

    FileError error(&#41; const;
    void unsetError();
    
    QString fileName() const;
    void setFileName(const QString &name);
    

    ......@

    Only if I remove the include of QFile, will the code runs.

    Notice that this problem is project specific. (see below)

    In order to find the source of errors, I also open another simple project that only has main.cpp like:
    @#include <QFile>
    #include <QTextStream>
    #include <iostream>
    #include <cstdlib>
    using namespace std;

    int main()
    {
    std::cout<<"Test\n";
    double data[2];
    data[0] = 1.2;
    data[1] = 2.3;

    QFile file;
    file.setFileName("C://Data.txt");
    file.open(QIODevice::ReadWrite | QIODevice::Text)
    
    cout<<"data[0]: "<<data[0]<<endl;
    cout<<"data[1]: "<<data[1]<<endl;
    
    QTextStream out(&file);
    
    out<<"Test outFile!\r\n";
    out<<1<<"\r\n";
    out<<2.2<<"\r\n";
    out<<"End";
    
    file.close();
    return 0;
    

    }@

    This small example wroks just fine, and there is no compiler error. It shows that <QFile> works fine in this small project.

    The .pro file of my original project (modified oscilloscope example from Qwt) is:

    @include( $${PWD}/../examples.pri )

    TARGET = oscilloscope

    HEADERS =
    signaldata.h
    plot.h
    knob.h
    wheelbox.h
    samplingthread.h
    curvedata.h
    mainwindow.h \
    data1902.h

    SOURCES =
    signaldata.cpp
    plot.cpp
    knob.cpp
    wheelbox.cpp
    samplingthread.cpp
    curvedata.cpp
    mainwindow.cpp
    main.cpp
    data1902.cpp

    win32: LIBS += -LC:/ADLINK/UDASK/lib/ -lusb-dask # <-- 3rd party library

    INCLUDEPATH += C:/ADLINK/UDASK/include

    DEPENDPATH += C:/ADLINK/UDASK/include@

    and the .pro file for "simple project" :

    @QT += core

    QT -= gui

    TARGET = TextFileIO
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp@

    I am not sure what's going on there, in my "original project" I cannot simply include the QFile library.
    Thanks in advance.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Did you try to add the
      @QT += core@
      to your failing pro file? It tells the compiler to include the QtCore libraries.
      When you need GUI elements, you should also include gui
      @QT += gui@

      Greetz, Jeroen

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tay2510
        wrote on last edited by
        #3

        [quote author="Jeroentje@home" date="1390214349"]Did you try to add the
        @QT += core@
        to your failing pro file? It tells the compiler to include the QtCore libraries.
        When you need GUI elements, you should also include gui
        @QT += gui@
        [/quote]

        Thank you, I've added them but it doesn't change anything. I think the examples.pri offered by Qwt might already included them. Here is the examples.pri file included in my project's .pro file:

        @################################################################

        Qwt Widget Library

        Copyright (C) 1997 Josef Wilgen

        Copyright (C) 2002 Uwe Rathmann

        This library is free software; you can redistribute it and/or

        modify it under the terms of the Qwt License, Version 1.0

        ###################################################################

        QWT_ROOT = $${PWD}/..
        include( $${QWT_ROOT}/qwtconfig.pri )
        include( $${QWT_ROOT}/qwtbuild.pri )
        include( $${QWT_ROOT}/qwtfunctions.pri )

        TEMPLATE = app

        INCLUDEPATH += $${QWT_ROOT}/src
        DEPENDPATH += $${QWT_ROOT}/src

        !debug_and_release {

        DESTDIR      = $${QWT_ROOT}/examples/bin
        

        }
        else {
        CONFIG(debug, debug|release) {

            DESTDIR      = $${QWT_ROOT}/examples/bin_debug
        }
        else {
        
            DESTDIR      = $${QWT_ROOT}/examples/bin
        }
        

        }

        QMAKE_RPATHDIR *= $${QWT_ROOT}/lib

        contains(QWT_CONFIG, QwtFramework) {

        LIBS      += -F$${QWT_ROOT}/lib
        

        }
        else {

        LIBS      += -L$${QWT_ROOT}/lib
        

        }

        qwtAddLibrary(qwt)

        greaterThan(QT_MAJOR_VERSION, 4) {

        QT += printsupport
        QT += concurrent
        

        }

        contains(QWT_CONFIG, QwtOpenGL ) {

        QT += opengl
        

        }
        else {

        DEFINES += QWT_NO_OPENGL
        

        }

        contains(QWT_CONFIG, QwtSvg) {

        QT += svg
        

        }
        else {

        DEFINES += QWT_NO_SVG
        

        }

        win32 {
        contains(QWT_CONFIG, QwtDll) {
        DEFINES += QT_DLL QWT_DLL
        }
        }
        @

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          Sometimes rerunning of qmake and rebuild helps. Maybe something in your makefile is mixed up.

          Furthermore, did you check the compile errors from start?
          It helps significantly to solve them in sequence, because rest may be dependent error messages.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tay2510
            wrote on last edited by
            #5

            Thank you for your suggestions. I've tried qmake and rebuilding option, but those errors remain. Most of the 300+ errors point to qfile.h, few to the .h or .cpp file that includes qfile.h (I move the inclusion all around my project for testing, when I include it in main.cpp, there are still 90+ errors).

            1 Reply Last reply
            0
            • K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              Probably the best is to go step-wise.

              Checkout your Qt SDK installation first. Generate in Qt creator a fresh "Qt console application" and also a "Qt GUI application". Do not change anything in there. You should be able to compile and run without an issue.

              Next step you should be able to build qwt and its examples without problems as long as it is in its original state.
              I have done this successfully for Qwt v6.0.1 and v6.1.0 with MinGW compiler.

              I do not see a reason why there should be a problem with QFile. However, I do not use it. I simply use the standard file IO (ifstream and ofstream) of C++. So I am not of help in regard of QFile.

              However the first steps up to compile and running the examples of qwt should already verify if there is a general problem with your setup.

              When anything comes up, you need to post at least the couple of lines of your compile output.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Tay2510
                wrote on last edited by
                #7

                Thank you for the advices. I've bypassed the error by using C++ standard file IO. Nevertheless there is some problems with QFile. To identify if this is really a glitch, I'll come back and check this out step-wise once I finish my main project.

                1 Reply Last reply
                0

                • Login

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