Results 1 to 5 of 5

Thread: How can write text in a file in 32bit qt installed on x64 windows 7

  1. #1
    Join Date
    Oct 2012
    Location
    Gurgaon, Haryana, India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question How can write text in a file in 32bit qt installed on x64 windows 7

    Hi,
    I am newbie in qt. i want to write text from my qt application into a file, but file isn't created. i try to print the error occured during file creation... error is " unknown error". My qt is 32 bit & i have installed it on x64 window7. i have done same thing on 32 bit windows 7 but there in no problem. so plz help me for this. Thanks in advance.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can write text in a file in 32bit qt installed on x64 windows 7

    Here is what we know: you have tried to create a file and it failed... hardly a lot of information to go on.

    The mostly likely causes are: the path you have used does not exist or you do not have permission to write in that location. We have no way to know.

  3. The following 2 users say thank you to ChrisW67 for this useful post:

    berzasnon (4th October 2012), Pardeep (5th October 2012)

  4. #3
    Join Date
    Oct 2012
    Location
    Gurgaon, Haryana, India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How can write text in a file in 32bit qt installed on x64 windows 7

    It may be, but i write same code on 32 bit machine also, there is no such problem.
    Below is code that i write on both machine.

    QFile file("../styleSheetFile.txt");
    if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
    QMessageBox *msg = new QMessageBox();

    msg->setWindowTitle("Error Message");
    msg->setText("Can't open file");
    msg->show();
    }
    else
    {
    QTextStream out(&file);
    out <<textEdit->text();
    }
    file.close();

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How can write text in a file in 32bit qt installed on x64 windows 7

    It may be, but i write same code on 32 bit machine also, there is no such problem.
    Think about it a bit harder; if there is no such problem then it either works or you can tell me what other scenario caused the issue.

    You are using a relative path, a recipe for disaster unless you tightly control the current working directory. What is the current working directory of the process? Usually, unless you do something to change it, the working directory with be "C:\Program Files(x86)\MyApp"; this directory and the one above it will not be writable to unprivileged processes. If the current working directory is the root of a drive then there is no parent directory to write into.

    Windows has recommended locations for persistent application data. Some of them are locatable using QDesktopServices. You probably should use them.

    BTW: Your error message box is a memory leak. You would usually put this on the stack and use exec() rather than show().

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

    Pardeep (5th October 2012)

  7. #5
    Join Date
    Oct 2012
    Location
    Gurgaon, Haryana, India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: How can write text in a file in 32bit qt installed on x64 windows 7

    Thank you very much. I have created file now on 64 bit system too.Thank You again.

Similar Threads

  1. Replies: 1
    Last Post: 7th December 2011, 16:08
  2. Write on a text file from QString
    By Malek in forum Newbie
    Replies: 3
    Last Post: 27th December 2010, 19:27
  3. How to write something on a text file on a certain line?
    By Bong.Da.City in forum Qt Programming
    Replies: 1
    Last Post: 17th December 2010, 21:01
  4. Write one value per line in text file
    By babygal in forum Newbie
    Replies: 11
    Last Post: 1st December 2010, 06:47
  5. How to write ByteArray into a text file?
    By babygal in forum Newbie
    Replies: 4
    Last Post: 11th October 2010, 04:19

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.