Results 1 to 19 of 19

Thread: open a file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default open a file

    Dear All

    I have file in c:\windows\local files\temp\picture.jpg, I would like to open the file. How can I do it?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: open a file

    if you need just open the file then use QFile, if you need to show this image then use QPixmap.

  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: open a file

    the problem is not only a image, we have word files, excel files, we could read the file, but we could not open it.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: open a file

    please, show code what we do.

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: open a file

    Qt Code:
    1. QFile *tmpFile = new QFile ( QString ( QDir::tempPath() + "/" + tmpFile->fileName() ) );
    2. if ( !tmpFile->open ( QIODevice::WriteOnly) )
    3. {
    4. return;
    5. }
    6. qint64 size = tmpFile->write ( ba1 );
    7. if ( size != -1 )
    8. {
    9. tmpFile->setFileName(realname);
    10. QProcess::startDetached ( tmpFile->fileName() );
    11. }
    To copy to clipboard, switch view to plain text mode 

    After this it saves the file to temp folder but I would like to open the file after that.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: open a file

    if you cooment this line
    Qt Code:
    1. ...
    2. QProcess::startDetached ( tmpFile->fileName() );
    3. ...
    To copy to clipboard, switch view to plain text mode 
    and then try to open this file, does it open?

  7. #7
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: open a file

    Quote Originally Posted by spirit View Post
    if you cooment this line
    Qt Code:
    1. ...
    2. QProcess::startDetached ( tmpFile->fileName() );
    3. ...
    To copy to clipboard, switch view to plain text mode 
    and then try to open this file, does it open?
    Yes, I try to open the file, I mean like if it is a openoffice file I would like to start open office to see the file.

    But what I think is QProcess::startDetached ( tmpFile->fileName() ); doesnt work...

  8. #8
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: open a file

    Quote Originally Posted by aekilic View Post
    But what I think is QProcess::startDetached ( tmpFile->fileName() ); doesnt work...
    Of course not. If we take an open office file as example, you are trying to execute the .odf file with QProcess, not the .exe.

  9. #9
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: open a file

    ok then should I write,

    Qt Code:
    1. QProcess::execute( tmpFile->fileName() );
    To copy to clipboard, switch view to plain text mode 
    ??

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: open a file

    your file isn't executable. you need specify needed program and your file as an argument.
    somethig like this will work
    Qt Code:
    1. QProcess::execute("notepad.exe", QStringList() << "d:/phones.txt");
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: open a file

    for the file, I never know what the user saves,

    It could be pdf, odt, dwg? So I dont know the program, any way to do it withour writing the program.

  12. #12
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: open a file

    What do you mean with 'open the file after that'? What you do is write it to disk and afterwards you try to start it as executable.

Similar Threads

  1. Replies: 5
    Last Post: 29th October 2007, 22:49
  2. open large file in qt?
    By vishal.chauhan in forum Qt Programming
    Replies: 11
    Last Post: 29th May 2007, 07:25
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  4. Restrict user to open the same file
    By vermarajeev in forum General Programming
    Replies: 33
    Last Post: 25th May 2007, 08:15
  5. How to open a Pdf file from Qt
    By vishal.chauhan in forum Newbie
    Replies: 2
    Last Post: 28th March 2007, 08:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.