Thread: Can not open file ( Qt )

  1. #1
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694

    Can not open file ( Qt )

    Ok I have a file with constant name and want to open it.

    I am using Qt framework and I am on Mac.

    The path of my project is :
    ~Desktop/RayTracerFrameWorkOOP/
    (here I have everything, header, source files and all the relevant files of Qt)
    Here I have the file that I need to read from too. What I think is remarkable is that the file is of kind : Unix executable file

    From Qt IDE I open the project from the recent projects option with this path :
    ~Desktop/RayTracerFrameWorkOOP/QImageViewer.pro

    Here is the code
    Code:
      ifstream in("icosahedron_0.off");
        if (!in) {
            cout<<"\nError reading file."<<endl;
            exit(0);
        }
    and when I execute the program I am receiving the Error reading file message.

    Any ideas?
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The real question is, where is your executable (the result of the build process) and where is your data file? Unless they're in the same directory or the data file is in the directory QtCreator uses as the working directory when you launch, it won't find it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Great point! I wasn't aware of that.
    When I execute I get this
    Code:
    /Users/usi/Downloads/QImageViewer-build-desktop-Qt_4_8_3__local__Release/QImageViewer.app/Contents/MacOS/QImageViewer exited with code 0
    And so I went to the file and put the file into it ( Also the folder models has the file which I am interested in )
    The image is taken in file QImageViewer-build-desktop-Qt_4_8_3__local__Release
    Can not open file ( Qt )-screen-shot-2012-12-06-11-48-14-am-jpg
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Well, we were instructed to put the absolute path, because nobody could open it.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Open file?
    By Therry in forum C++ Programming
    Replies: 6
    Last Post: 04-15-2012, 02:57 AM
  2. Cant open file
    By Pota in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2011, 06:08 AM
  3. Replies: 3
    Last Post: 03-08-2010, 02:43 PM
  4. Open File/Save File crashes on cancel?
    By Blackroot in forum Windows Programming
    Replies: 0
    Last Post: 08-02-2008, 02:16 AM
  5. Replies: 12
    Last Post: 03-10-2005, 07:48 PM