Results 1 to 5 of 5

Thread: How to create File in a given Dir ?

  1. #1
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default How to create File in a given Dir ?

    Hi,

    I want to create a File in a given Directory.

    f.e.:

    Qt Code:
    1. QFile myFile("C:/Home/File.txt")
    To copy to clipboard, switch view to plain text mode 

    doing it the way above Qt doesnt create any File. I want to create a QDir (that works fine) and save all created Strems inside this QDir. Can anybody help?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to create File in a given Dir ?

    Open the file in write mode.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2011
    Posts
    26
    Thanks
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create File in a given Dir ?

    this is my code:

    Qt Code:
    1. QString str = QCoreApplication::applicationDirPath()+"/hello/";
    2. qDebug() << str;
    3.  
    4. QFile Druck_m(str+"Druck.m");
    5. Druck_m.open(QIODevice::WriteOnly);
    6. QTextStream dataDruck_m(&Druck_m);
    7.  
    8. ........stream
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to create File in a given Dir ?

    And? What about it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to create File in a given Dir ?

    Does the "hello" dir exists ? If not, you will probably get QFile::OpenError when trying to create a file in a non-existing directory.
    You need to check return values, they can help a lot:
    Qt Code:
    1. QString str = QCoreApplication::applicationDirPath()+"/hello/";
    2. QFile Druck_m(str+"Druck.m");
    3. if( Druck_m.open(QIODevice::WriteOnly) ){
    4. QTextStream dataDruck_m(&Druck_m);
    5. ...
    6. } else{
    7. qDebug() << "file not opened, error code: " << Druck_m.error(); // error codes are desribed in QFile documentation
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to stampede for this useful post:

    revellix (10th October 2011)

Similar Threads

  1. How to create a .sis file?
    By mport9491 in forum Newbie
    Replies: 1
    Last Post: 17th August 2011, 19:05
  2. How to re-create .deb file ???
    By rickrvo in forum Newbie
    Replies: 1
    Last Post: 10th February 2011, 16:49
  3. Cannot create file
    By sharpsword in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 20th April 2010, 14:08
  4. Create DLL file from Qt4
    By abghosh in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2010, 18:25
  5. how to create *.cpp file fm *.ui
    By Shuchi Agrawal in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 21:07

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.