Results 1 to 5 of 5

Thread: Qt4 Gui application cannot write to file

  1. #1
    Join Date
    Dec 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt4 Gui application cannot write to file

    I have a Gui application from which i have to write a timestamp along with the image number, so i have a code like this:

    MyCameraWindow::MyCameraWindow(QWidget *parent) : QWidget(parent) {

    .......................
    timestampFile = fopen ( "timestamps.txt", "w");
    .......................
    }

    void timestamp (FILE *out, int nframe){

    struct tm *tmp;
    time_t t;

    t = time (NULL);
    tmp = localtime (&t);

    fprintf (out, "%4d\t%02d.%02d.%04d %02d:%02d:%02d\n", nframe, tmp->tm_mday,
    tmp->tm_mon+1, tmp->tm_year+1900, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
    }

    void MyCameraWindow::timerEvent(QTimerEvent*) {

    for (int i=0; i < cameraCount; i++) cvGrabFrame (camera[i]);

    if (recordFlag == 1) timestamp(timestampFile, ++frameNo);
    for (int i=0; i < cameraCount; i++){
    ................
    }
    }

    The file is being created but nothing is written, i cannot figure why! ... can someone tell me how to write to a file in Gui application?

  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: Qt4 Gui application cannot write to file

    Did you start the timer?
    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
    Dec 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 Gui application cannot write to file

    yes i did. Also if i put a printf statement before fprintf i can see the output.

  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: Qt4 Gui application cannot write to file

    Maybe it's time you stopped using C and started using C++ and Qt? How about replacing fprintf() with QFile? If you want to stick with C, make sure fopen() succeeds in opening the file. But it'd really be simpler if you used what Qt offers - QFile and QDateTime in this case.
    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
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt4 Gui application cannot write to file

    I see no fclose or fflush, so the file will be empty as the data will just be buffered until then.

    But I also agree with wysota - if your using Qt, you really should be using Qt classes (or at least C++) rather than standard C.

Similar Threads

  1. how to write a sample application using QT on windows mobile
    By pallavi Boyapat in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2008, 06:10
  2. how to write hello world sample QT application on windows mobile
    By pallavi Boyapat in forum Qt Programming
    Replies: 8
    Last Post: 3rd November 2008, 12:06
  3. How to execute an exe file from Qt application
    By maveric in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2008, 10:24
  4. FSWriteFork in MAC OS to write data to a file.
    By vishal.chauhan in forum General Programming
    Replies: 5
    Last Post: 2nd July 2007, 06:48
  5. Opening pdf file in Qt application
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2007, 18:35

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.