QFileDialog::getOpenFileName doesn't set the initial directory on Mac OS 10.8 Mountain Lion - macos

I can not change the current directory with QFileDialog with Qt 4.8. The same code works fine on Windows and Mac OS 10.6 Snow Leopard. It also works fine if I don't use the native Mac OS X dialog.
This works:
fn=QFileDialog::getOpenFileName(this,"Select File","/Users/myuser/Desktop",QString(),0,QFileDialog::DontUseNativeDialog);
This doesn't work:
fn=QFileDialog::getOpenFileName(this,"Select File","/Users/myuser/Desktop");
It looks like if most of the time it opens the last path of the last call to getOpenFileName.

Got the same issue with Qt5.2.0 on Mavericks...
I found a work around: append a dummy file name to the directory you want to select.
However, be sure not to do this on Windows because the user will see it.
QString dir = "/Users/myuser/Desktop";
#if defined(__APPLE__)
dir += "/MyFile.txt";
#endif
fn = QFileDialog::getOpenFileName(this, "Select File", dir);
Also, for those like me that instantiate a file dialog because they need more options you can also do:
QFileDialog fileDialog(this, "Select File");
#if defined(__APPLE__)
fileDialog.selectFile(dir + "/MyFile.txt");
#else
fileDialog.setDirectory(dir);
#endif
...

This is a bug in Qt that is reportedly fixed in Qt 5.0.1 and Qt 4.8.4 (though it seems that it still reproducible in 4.8.4 by people (myself included)).
This bug has been reported in JIRA as QTBUG-20771, QTBUG-28161 and finally QTBUG-35779 (which appears to have finally fully resolved the issue in Qt 5.2.1). Here is a link to the patch in Gerrit.

Related

QT Creator - iostream no such file or directory (Mac)

I have program in QT Creator3.4.2 (Macbook El Capitan).
The line #include <iostream> was under lined and says no such file or directory.
How to resolve this issue ?
Its because I just updated the XCODE and haven't accepted the terms and condition.
I just accepted the T&A and restarted, its works fine now...

dylib library path and use it in application

I want to create a library in Mac OS X El Capitan (10.11.x) and use it in another application by qt creator, so I’ve created a simple library in qt with this setting:
QT -= gui
TARGET = /System/Library/Frameworks/MyFrm.framework/dylib/DynminLinkingLib
TEMPLATE = lib
As you can see I’ve created “DynminLinkingLib” library in MyFrm framework; after that I created a Qt Application to use the library.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SampleProject
TEMPLATE = app
macx: LIBS += -L/System/Library/Frameworks/MyFrm.framework/dylib -lDynminLinkingLib.1.0.0
INCLUDEPATH += /System/Library/Frameworks/MyFrm.framework/include
When I run my application in qt, it gives me this error:
dyld: Library not loaded: libDynminLinkingLib.1.dylib
Referenced from: /Users/mac/Src/dll/DynamicLinking/build-SampleProject-Desktop_Qt_5_5_0_clang_64bit-Debug/SampleProject.app/Contents/MacOS/SampleProject
Reason: image not found
The program has unexpectedly finished.
For resolving this error in Qt projects, I set DYLD_LIBRARY_PATH variable to /System/Library/Frameworks/MyFrm.framework/dylib and it works well, but when I run bundle application it doesn’t work and gives me this error:
enter image description here
This is because of “libDynminLinkingLib.1.dylib” is not in application path.
otool -D /System/Library/Frameworks/MyFrm.framework/dylib/libDynminLinkingLib.1.0.0.dylib
libDynminLinkingLib.1.dylib
I have two questions:
I know how to solve this problem by install_name_tool but I want solve this problem in qmake and .pro file. So how can I solve this problem by pro config file?
In El Capitan, I can not use DYLD_LIBRARY_PATH because of security reasons. In order to use it I must deactivate SIP (system integrity protection). So is there any way to use DYLD_LIBRARY_PATH without deactivating SIP?
This isn't a full solution but if you just want some local libraries you've built to be included while building something else you can create ~/lib and ~/include folders and put the files there. Those folders are on the default path.
https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/UsingDynamicLibraries.html

Where does /usr/include/mach-o/loader.h come from?

It seems that some of my Mac OS X systems have /usr/include/mach-o/loader.h and others don't. I'm confused because this file is documented here:
https://developer.apple.com/library/mac/#documentation/developertools/conceptual/MachORuntime/Reference/reference.html
For example:
...Declared in /usr/include/mach-o/loader.h. See also mach_header_64.
Does anyone know if this file was removed on any newer versions of Mac OS X? Or if I need to install a special SDK to get it?
It exists on my Mac (OS X 10.7), but I do have Xcode installed and it might have come as part of that.
Edit
Note that when Xcode compiles anything, it doesn't use the headers in /usr/include but the ones in the SDK you have chosen and you can find out where the system headers are by doing a compile and then checking the -isysroot command line switch. So I have just done a compile and the compiler invocation includes:
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7sdk
If you open that directory, you'll find it contains a usr/include/mach-o subdirectory with the file you want in it.
loader.h is a hidden file on MAC, so if you don't have hidden files viewable open up a terminal first do this command:
defaults write com.apple.finder AppleShowAllFiles TRUE
then this command:
killall Finder
After that follow the path in the finder: /usr/include/mach-o/loader.h
If you do have hidden files all I can say is that I have a OS X 10.7, 10.6 and 10.5 laptop and they have it and have Xcode installed to.

Cg Framework not being recognized by XCode 3.2.6

I have Cg installed to /Library/Frameworks/Cg.framework. It looks like this on disk:
My XCode 3.2.6 project has Library/Frameworks as a Framework Search Path and -Framework Cg in "Other Linker Settings" but when I try to #include <Cg/cg.h> it can't find the file. If I directly add /Library/Frameworks/Cg.framework/Headers to my "Header Search Paths" I can `#include ' but it fails to link with error "Framework not found Cg".
I don't really understand what a Mac Framework is - is it anything special or just a regular directory? It seems as if Xcode simply doesn't understand /Library/Frameworks/Cg.framework is a framework for some reason.
I'm not sure if this is related: https://stackoverflow.com/questions/5293940/xcode-3-2-6-stops-looking-in-library-frameworks
Any help understanding what's wrong would be appreciated.
I tested a simple test from the command line:
test.cpp
#include <Cg/cg.h>
void f()
{
CGcontext context = cgCreateContext();
}
Just running "gcc -c test.cpp" succeeds (-c says don't link). I also ran "gcc -M test.cpp" (list dependencies): /Library/Frameworks/Cg.framework/Headers/cg.h So the framework seems fine... how can running gcc without passing any search paths work, but XCode can't see the framework when it calls gcc?
I think you did not added the Cg framework to the project properly. Click on your target -> click Build Phases (a tab)->in "Link Binary with Libraries" click + sign -> fin Cg framework and add it. Now the following should compile just fine:
#include <Cg/cg.h>
void a() {
CGcontext context = cgCreateContext();
}
I also presume that you installed the framework using the provided image (Cg-something.dmg)
You dont have to alter any search path manually. When the framework is added as shown above, the compiler will look there.
I'm not sure if this is relevant, but I was having similar problems with the CG library. It would link with 10.5 but not 10.6. I eventually realized that my 10.6 sdk directory was messed up: instead of /Developer/SDKs/MacOSX10.6.sdk/Library having a sym link to the Frameworks directory in it, it had a Frameworks directory with a sym link inside the Frameworks directory.
It should have worked anyway (I had supplied the absolute path for the cg framework AND added the /library/frameworks directory to the search path) but it didn't. Actually, why anything linked properly with the 10.6 sdk directory messed up in the first place, I don't know...
Well I have an answer as to why, but not how. Cahnging the SDK from 10.6 to 10.5 meant things magically worked. BUT both SDK dirs on disk have identical links to the correct Frameworks dir, and this is a clean 10.6 install not an upgraded 10.5 machine, so no idea why. Anyone who can write an answer explaining this and ideally offering a solution is welcome to the bounty!

Can we set "-fno-jump-tables" as “Other Cflags” in XCode?

Is there a way to set "-fno-jump-tables" as “Other Cflags” in XCode. I tried setting it but it gives compilation error. The error reads something like this "i686-apple-darwin10-gcc-4.2.1: fno-jump-tables: No such file or directory".
I am using gcc version 4.2. Mac OS X 10.6.8. Xcode version is 3.2.6.
Regards,
Vishvesh
It works fine for me from the command line.
gcc -fno-jump-tables foo.c
From the error, it looks like the leading - is getting lost and fno-jump-tables is being treated as a file. I assume you are putting -fno-jump-tables in "other C flags" and not just fno-jump-tables

Resources