Skip to content

Latest commit

 

History

History
116 lines (65 loc) · 5.53 KB

CppQFileExample1.md

File metadata and controls

116 lines (65 loc) · 5.53 KB

 

 

 

 

 

 

QtQt CreatorLubuntu

 

QFile example 1: copying file and checking if the copy exists is a QFile example.

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • Qt Qt: version 5.4.1 (32 bit)
  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppQFileExample1/CppQFileExample1.pro

 


exists(../../DesktopApplication.pri) {   include(../../DesktopApplication.pri) } !exists(../../DesktopApplication.pri) {   QT       += core gui   greaterThan(QT_MAJOR_VERSION, 4): QT += widgets   win32 {     greaterThan(QT_MAJOR_VERSION, 4): QT += svg   }   TEMPLATE = app   CONFIG(debug, debug|release) {     message(Debug mode)   }   CONFIG(release, debug|release) {     message(Release mode)     DEFINES += NDEBUG NTRACE_BILDERBIKKEL   }   QMAKE_CXXFLAGS += -std=c++1y -Wall -Wextra -Weffc++   unix {     QMAKE_CXXFLAGS += -Werror   } } exists(../../Libraries/Boost.pri) {   include(../../Libraries/Boost.pri) } !exists(../../Libraries/Boost.pri) {   INCLUDEPATH += \     ../../Libraries/boost_1_55_0 } SOURCES += main.cpp

 

 

 

 

 

./CppQFileExample1/main.cpp

 


#include <cassert> #include <cstdio> #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #include <QFile> #pragma GCC diagnostic pop int main(int /* argc */, char* argv[]) {   //Copy executable (argv[0] is this executable its full path)   QFile me(argv[0]);   const std::string temp_filename = "tmp";   me.copy(temp_filename.c_str());   //Check that copy exists   assert(QFile::exists(temp_filename.c_str()));   //Delete the copy   std::remove(temp_filename.c_str());   assert(!QFile::exists(temp_filename.c_str())); }