QFile does not create file on mac - qt

I use this code (this is qt sample)
QFile file("out.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&file);
out << "The magic number is: " << 49 << "\n";
I cant find file "out.txt" on mac. How to fix it?

Several Problems here :
Firstly you are not checking what is the return value of file.open().
Only if true will it actually create the file.
Also relative path so the file will be created at the application working directory when you call the open() method.
Also you will need write permission for the user in the directory for the file to be created.
You can check error stream for any errors that it will throw.

The file is writing to your apps package contents sitting next to the executable..
yourApp/Contents/MacOS/out.txt
I don't know how to get a file to write outside of the package contents though..

On the line:
QFile file("out.txt");
You need to specify all the root on mac!!

You should check your home directory. It should be there.

Related

While click run in my project i am getting "Failed to start program. Path or permissions wrong?"

While click run on my project in qt creator
" Failed to start program. Path or permissions wrong?"
11:02:18: Starting C:\V6\Filename2.0\release\Filename.exe...
11:02:18: Failed to start program. Path or permissaions wrong?
11:02:18: C:/V6/Filename2.0/release/Filename.exe exited with code -1
11:02:18: The process failed to start. Either the invoked program "C:/V6/Filename2.0/release/Filename2.exe" is missing, or you may have insufficient permissions to invoke the program.
Without more information (Qt and Qt Creator version, OS version - I assume it's windows) it's difficult to formulate a sensible hypothesis, however, off the top of my head some things you might try:
are you sure there's not another Filename.exe running? if there is QtCreator cannot create a new executable replacing current one that is in use
maybe windows holds some lock on that particular file / folder, it might be worth checking with tools like mst isusedby
try closing QtCreator / rebooting to clean any stale locks on that folder
in the projects section choose another folder for shadow building and see if the executable can be created there.
It could be due to executable file name , as pointed out in this answer : Qt: Cannot execute '': The requested operation requires elevation that shows another error message, this happens if executable file name contains or ends with "install", "update", "setup", "patch".
On the other hand, its possible to explicitly set (access level) manifist in the .pro with Admin privileges required:
QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\"
Or, to set access for current user:
QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'asInvoker\' uiAccess=\'false\'\"
A bit late, but I have had this issue, caused by a target flag set as :
TARGET = runme.exe
in my .pro file.
Removing the extension,and changing it to just :
TARGET = runme
has solved this issue for me.

Couldn't canonicalise: No such file or directory

I am getting Couldn't canonicalise: No such file or directory error while getting single file using sftp.
here is what I am doing,
#!/bin/ksh
. /feeds/scripts/files.properties
filename=$1.txt
echo $filename
sftp $getusername#$getserver << EOF >> $logfile
cd /feeds/out/data/
lcd /feeds/files/
get $filename
bye
EOF
I am able to print/echo file name, but while executing scripts I am getting below error,
user:/feeds/scripts> ./fileReceiver.sh sample
sample.txt
Connecting to xxxxx.xxx.xxx...
Couldn't canonicalise: No such file or directory
Couldn't stat remote file: No such file or directory
File "/u/user/sample.txt" not found.
I don't know why it adds '/u/user' before file name. Can anyone please help?
Thanks in advance.
Solved!, I am sorry, my mistake. In property file, I had mentioned wrong server name. Server names looks very similar so couldn't figure it out. Anyways, thanks #devnull, I gone through it, its useful.
For me solution was removing / from directory name at end
Non-working
/folder-name/
Working
/folder-name

Transmitting an exe file via network in Qt

I am trying to create a Remote compiling system in Qt. What I am trying to do is to get the C/C++ source from the client and calling the locally available GCC via QProcess on the server, create the exe file and then transmit the exe back to the client. Simple right?
The exe file is being generated perfectly but Qt is just not able to read the file into an array to transmit it.
My Code is:
QByteArray arr;
qDebug() << "To Client: exe";
QFile f("compiled.exe");
qDebug() << f.exists(); //output = false
QString path = QDir::toNativeSeparators(QFileInfo(f).absoluteFilePath());
qDebug() << path; //perfect path is coming
qDebug() << f.open(QIODevice::ReadOnly); //output = flase
arr = f.readAll(); // size of arr is 0
f1.close();
client->write(arr); //zero bytes written
Although the exe file is very much present, I am getting such outputs. I tried with other files in the same directory, it works absolutely perfectly. Only exe files wont work.
I am using Qt 4.8.1 32 bit on Windows using MSVC v16.00.40219.10 as the compiler.
Thanks in advance!!
No need to speculate, there is a description of error codes when using QFile::open().
Btw
qDebug() << f.exists(); //output = false
It seems compiled.exe is not in the process working directory, neither nor in any direcotry in path. Provide the complete path...

PHPExcel exception: "Could not close zip file ... "

I am using XAMPP a Mac for local development, but I used this code at work (using Windows and an otherwise identical development environment) and it worked fine:
$objPHPExcel = new PHPExcel();
$sheet = $objPHPExcel->createSheet();
$sheet->fromArray($a);
...
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save('P:/Projects/Mess3/Sadness.xlsx');
$objWriter->save('/Users/tjb1982/Desktop/sadness.xlsx');
The commented-out text works with my Windows system at work. I tried to output the file to 'php://output' and got a garbled mess (is that what is to be expected?).
I can't seem to find anyone who is experiencing this problem outside of those who had permissions problems or had the file open when they were trying to save it. Please help!
I was getting the same error "Cannot close zip file.." and realized it didn't have permissions to write to that directory. Check your write permissions. (IIS8 + php + mysql + oracle)
Once i allowed write permissions problem was immediately fixed.
Generally this means one of 3 things:
The directory where you're trying to save the file doesn't exist
The directory/file has permissions that preclude you from writing to it
The file is already open in some other application, or has a lock on it
I had the same problem, just added the path in the save method and it worked
$objWriter->save(dirname(FILE)."dir1"."/".$file.".xlsx");
I found that this problem is caused when you execute the code once and then open the outputted excel file with Office excel. Try closing the file in excel and then try! Hope this helps!
I had the same problem, actually you have to modify the basic rights of reading and writing given to your PHPWord directory:
chmod -R 777 PHPWord/

Console input with Qt Creator

I'm developping a very simple app on my Mac using QtCreator.
It's a console application and I want the user to enter its name, and then I display his name. Here is the code :
#include <iostream>
int main(int ArgC, char* ArgV[])
{
char Name[1000];
std::cout << "Type your name : ";
std::cin >> Name;
std::cout << "Hello " << Name << "\n";
return 0;
}
When running this app with QtCreator, the string "Type your name :" is displayed in the 'Application Output' tab. But if I type some text and press the enter key, nothing is happening.
What's wrong ?
I found a solution. With Qt Creator 1.3.0 (on Mac OS X), here is what I had to do :
Project->Run settings, check "Run in Terminal" (thanks Ropez)
Qt Creator->Preferences : Environnement : General : Terminal : I had to put the whole path to XTerm. For my config, I had to put /usr/x11/bin/xterm -e.
Now, everything is working fine !
Go to Project -> Run settings, and make sure "Run in Terminal" is checked.
BTW:
std::cin >> Name;
is probably not what you want. It will read just a single token (typically only the first name). You should have a look at getline, or the string version.
Jeromes solution is the proper one. Though I can give you a different alternative. In case you don't want to use X11 (for some reason anyhow) in the same position (QtCreator->Preferences->Environment:General:Terminal) you can give your path to the Terminal application like this:
/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
Enjoy!
Solution for Windows.
In the .pro file add:
QT -= core gui
TEMPLATE = app
CONFIG += console
Go to Project -> Run settings, and make sure "Run in Terminal" is checked.
I had the "Cannot start the terminal emulator 'xterm'" problem on Mac and fixed it by going to settings, Environment and clicking the "Reset" button next to the Terminal text field.
For some reason by default it just said "xterm -e" but after the reset it became an absolute path of "/usr/X11/bin/xterm -e".
My console app then ran fine.
For Mac-based Qt 2.4.0, click on the Project vertical tab, which is located below the "Debug" along the same vertical line as Welcome, Edit, Design. In Target-> Run, make sure "Run in terminal" is checked!

Resources