Results 1 to 4 of 4

Thread: create file in another directory

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default create file in another directory

    Hi everybody,

    OS: WINXP
    Compiler: MINGW
    QT: 3.4

    I can create a file in the same directory like my program is, but i would like to write this file in another directory (There where my program is i have a directory with the name "Reports". I would like to crate there

    here my code to create my file:
    Qt Code:
    1. //Time Test
    2. QDateTime dt = QDateTime::currentDateTime();
    3. QString datum = dt.toString();
    4.  
    5. datum.replace( ".", " " );
    6. datum.replace( ":", " " );
    7.  
    8. //file Name
    9. QString label = textLabel1->text();
    10. QString fileName = label + "_" + datum + ".csv";
    11.  
    12. QFile file( fileName );
    13. if ( file.open( IO_WriteOnly ) )
    14. {
    15. QTextStream stream( &file );
    16. stream << "Computername; Computertyp; Mitarbeiter; Abteilung; Bemerkung \n\n";
    17. for(int i = 1; i < (child + 1); i++)
    18. {
    19. QString spalte1 = (ergebnis_lv->currentItem() )->text( 1 );
    20. QString spalte2 = (ergebnis_lv->currentItem() )->text( 2 );
    21. QString spalte3 = (ergebnis_lv->currentItem() )->text( 3 );
    22. QString spalte4 = (ergebnis_lv->currentItem() )->text( 4 );
    23. QString spalte5 = (ergebnis_lv->currentItem() )->text( 5 );
    24.  
    25.  
    26. stream << spalte1 + "; " + spalte2 + "; " + spalte3 + "; " + spalte4 + "; " + spalte5 + "; " + "\n" ;
    27.  
    28. ergebnis_lv->setSelected((ergebnis_lv->currentItem())->itemBelow(), TRUE);
    29. }
    30.  
    31. }
    32. file.close();
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: create file in another directory

    Qt Code:
    1. QFile file( "Reports\\" + fileName );
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,710
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: create file in another directory

    Qt Code:
    1. QString path = "/some/path";
    2. QString fileName = path + label + "_" + datum + ".csv";
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: create file in another directory

    thanks for both fast replies

    it works perfect! Have a nice day
    Think DigitalGasoline

Similar Threads

  1. What is the best way to create a file management panel?
    By DIMEDROLL in forum Qt Programming
    Replies: 0
    Last Post: 24th September 2008, 08:49
  2. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  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. errors while installing Qt4.2 in Linux
    By nimmyj in forum Installation and Deployment
    Replies: 11
    Last Post: 13th December 2006, 11:58
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.