Qt/File

From ProgrammingExamples
< Qt
Revision as of 13:57, 6 February 2011 by Daviddoria (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

File.cpp

#include <iostream>
 
#include <QFile>
 
int main(int, char *[])
{
  QFile myFile("test.txt");
  if(myFile.exists())
    {
    std::cout << "File exists" << std::endl;
    }
  else
    {
    std::cout << "File does not exist" << std::endl;
    return 0;
    }
 
  if(myFile.open(QIODevice::ReadOnly))
    {
    std::cout << "opened successfully" << std::endl;
    }
  else
    {
    std::cout << "failed to open" << std::endl;
    }
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
PROJECT(File)
 
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
 
include_directories(${include_directories} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
 
ADD_EXECUTABLE(File File.cpp)
TARGET_LINK_LIBRARIES(File ${QT_LIBRARIES})