Hi all
Working on Qt4.2 on my Intel MAc
I am trying to open a file in read write mode using
But it returns -1 value.QIODevice::ReadWrite
I also tried usingthisO_WRONLY
then also its not working
What can I do Pls help.
Thanx
Hi all
Working on Qt4.2 on my Intel MAc
I am trying to open a file in read write mode using
But it returns -1 value.QIODevice::ReadWrite
I also tried usingthisO_WRONLY
then also its not working
What can I do Pls help.
Thanx
Always Believe in Urself![]()
Merry
Did you check if the file really exists/ you have to proper rights to open it in write mode? Don't think so...
Thanx 4 the reply
Might be But How to Check that Is I am having proper rights to open a file in Write mode.
and how can I get the permission.
Always Believe in Urself![]()
Merry
pls tell me how to get permissions for opening a file in read/write mode.
regards
merry
Always Believe in Urself![]()
Merry
Getting the permissions lies outside of Qt's responsibilities. Please check the documentation for QFileInfo:
"bool QFileInfo::isWritable () const" and friends may be able to help you.
Getting file permissions must be carried out by your operating system. On Linux you would do something like:
chmod a+w filexy to give everyone on your system writepermission for filexy. Of course you need to have the priviliges to do that (either you own the file or you are superuser). Every system has its own way to do that. Check your systems documentation for that.
Hi
If i login as a " root " then also i dont have permissions to open a file in read/write mode.
regards
merry
Always Believe in Urself![]()
Merry
Try to use this method after opening the file:
Qt Code:
To copy to clipboard, switch view to plain text mode
From the docs:
This should help you understand why the open fails.Returns the file error status.
The I/O device status returns an error code. For example, if open() returns false, or a read/write operation returns -1, this function can be called to find out the reason why the operation failed.
Well, can you tell us what permissions the file has? you may be root and still not have the proper permissions. On linux you can find out the premissions by using a command like "ls -l". There must be equivalent commands on MacOSX. Your user must have both read and write permissions. Also check if you can access the directory containing the file itself. Try a simple appilcation to see wheter you can open and close simple files. You should always try to create a minimal compilable version of the code to experiment so you can spot the bugs. I wrote you a simple test app that lets you open files and has a log teling you what went wrong if it fails to do so.
Qt Code:
#include <QApplication> #include <QtGui> { Q_OBJECT public: msgCount(0) { resize(800, 600); m_log->setStyleSheet("background-color:rgb(20,40,60); color:white;"); splitter->setOrientation(Qt::Vertical); splitter->addWidget(m_editor); splitter->addWidget(m_log); QList<int> sizes; sizes << 500 << 100; splitter->setSizes(sizes); setCentralWidget(splitter); setupMenus(); } private: QTextEdit* m_editor; QTextBrowser* m_log; int msgCount; void setupMenus() { fileMenu->addAction(tr("Open file"), this, SLOT(openFile())); fileMenu->addAction(tr("Exit"), this, SLOT(close())); } public slots: void openFile() { if (filename.isEmpty()) { return; } m_log->append( "* " + f.errorString()); return; } m_editor->setText(f.readAll()); f.close(); } }; #include "main.moc" int main(int argc, char* argv[]) { MainWindow mw; mw.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
Last edited by momesana; 7th November 2007 at 00:55.
Thanx for the reply
Actually i am not opening any directory or file , I am trying to open the drivename in read /write mode.
I used all the commands like "chmod 775" "ls-l" etc. but nothing works.
Is I need some special permissions to open " a drivename" in read/write mode.
regards
merry
Always Believe in Urself![]()
Merry
Well, I hope you are not trying to open "c:\" using QFile, because I doubt it will succeed ;-)
What do you mean by "drivename"? QFile opens _files_, so if you mean a device file as /dev/sda0 on Unix/Linux you are ok - as long as you have proper permissions.
Either check the permissions using "ls -l" or Konqueror/Nautilus/whatever file manager, or use the QFile::error() return value to know what error occurred.
Or, and this would be the best at this point, post the code snipped or some example you are using.
IOW: to open a _file_ in r/w mode use QFile:pen(QIODevice::ReadWrite). And stop.
There's noting else you can do in Qt. If you don't have proper permissions then you don't. It's not about Qt but about your operating system.
If you need to open a directory use QDir. But then you don't need to concern about open modes.
Are you trying to mount the drive, or just access it? OS X generally automounts so you should only be trying to open a folder (the mount point) or are you trying to work directly on a device to manipulate raw data (ie/ opening /dev/disk0 )? Is the drive a networked resource?
Hi
Thanx 4 d reply.
Actually i am trying to open Ipod's hard drive in read/write mode , I am trying to open raw file (i.e /dev/rdisk2) using filedescriptor. Its not opening the drive and filedescriptor returns -1 value.
I dont understand what to do and how to open the file in read/write mode..
Pls help
Regards
Merry
Always Believe in Urself![]()
Merry
First off, I don't have an ipod and I cant remember any distro creating a /dev/rdisk2 device, so I will assume /dev/rdisk2 exists and it points to your ipod. If it does not, it's not a Qt issue ;-)
Usually, to access a device file (/dev/something) you will need to be root or to set the proper permissions for that file.
I will assume that you have read/write privileges. If you don't know, open a shell/terminal and run the command "ls -l /dev/rdisk2". What is the output?
Now you can either use QFile directly:
Qt Code:
QMessageBox::warning(this, "Error", QString("Failed to open iPod device. Reason: ").append(file.errorString())); }To copy to clipboard, switch view to plain text mode
Or you can use a C file descriptor:
Qt Code:
FILE* fd = fopen("/dev/rdisk2"..... // get a file descriptor somehow QFile file; QMessageBox::warning(this, "Error", QString("Failed to open iPod device. Reason: ").append(file.errorString()));To copy to clipboard, switch view to plain text mode
If this does not help, please post the code snippet you are using or we won't be able to help you.
Bookmarks