Assistance with setting up Qt with my Mac?



  • So i apologies ahead of time for a very repeated question. Surely it has been asked numerous of time, and i hope to see a few sticky threads regarding this topic but i unfortunately did not encounter any. Now, this is the situation im having, i personally do not enjoy the Qt Creator IDE and would prefer to use my xCode which im already strongly familiared with. How can i set it all up together so that i can compile and use the xCode IDE rather than any other IDE. Also, please don't make fun of me but i never really learned to compile using the Command Line Tool for many crazy reasons!

    I would like to open up xCode and have an option to choose Qt and be able to build from there. If not, i'd like the simplest approach to been able to use Qt and xCode together? I've read a few sites that were really descriptive, that i must first create a simple main.cpp file, which i then using the Terminal, can create a .proj (dont remember the extensions by heart) and an xcodeproj as well! Which i then can open using xCode and begin to use xCode, but i also read that i must compile using the Command Line and qmake which i find a bit cumbersome.

    Also if your curiose, im using a MacBook Pro laptop, running the latest OS which i believe is Yosemite and i have xCode 6! If you need any other specs or have questions please dont hesitate on asking.

    PS: I tried once using Qt but i was intimidated by the way we had to set it up. now i return for a second chance and hopefully i can use this Framework rather than the other Libraries for C++ GUI.

    Thank You !

    UPDATE:

    I just ran into this link: http://qt-project.org/doc/qt-5/macosx-building.html Would i need to do this? I havent really read it so i have no idea what to do as of yet, this is so that i can just compile it thru command line rather than the Qt Creator?


  • Moderators

    Regarding your UPDATE: You do not need to build Qt from source, especially if you are new to it.

    As for using Xcode to develop Qt projects: it should be possible. You need to have Qt installed (go with the newest version available (5.3.2), it may already work with Xcode 6). All you need to do to generate Xcode files is to run qmake like this:
    @
    qmake -spec macx-xcode
    @

    in your project directory (where the .pro file is located). You may need to rerun this command when you update the project (add new files, remove old ones, change file names, etc.).

    From your post I gather that you don't have a .pro file yet (because you are just starting). In that case, indeed, you need to create some CPP files first (could be just main.cpp) and then run qmake in project creation mode. You will still need to run qmake again when you change project structure, because Xcode will not do it for you. At least as far as I know.



  • [quote author="sierdzio" date="1415604816"]Regarding your UPDATE: You do not need to build Qt from source, especially if you are new to it.

    As for using Xcode to develop Qt projects: it should be possible. You need to have Qt installed (go with the newest version available (5.3.2), it may already work with Xcode 6). All you need to do to generate Xcode files is to run qmake like this:
    @
    qmake -spec macx-xcode
    @

    in your project directory (where the .pro file is located). You may need to rerun this command when you update the project (add new files, remove old ones, change file names, etc.).

    From your post I gather that you don't have a .pro file yet (because you are just starting). In that case, indeed, you need to create some CPP files first (could be just main.cpp) and then run qmake in project creation mode. You will still need to run qmake again when you change project structure, because Xcode will not do it for you. At least as far as I know.[/quote]

    So I simply run that command to generate a .pro file which is what Qt reads correct? But before I generate that, I must already have a main.cpp created correct? So my question is this, must i generate a .pro every time I save in Xcode? Or when must I make it? Also will I be able to "Run and Build" normally using the Xcode or must I compile thru terminal? Will Xcode by default mark errors in the project when debugging since it's not linked to any specific library or framework or will it be okay since I have the .pro file (assuming my syntax is correct )?


  • Moderators

    I can't answer that with any degree of authority, because I've always tried to stay as far away from Xcode as possible; it's interface puts me off.

    Yes, I think (not sure!) you will need at least a main.cpp. But if you have more files with some project structure - even better. You do not need to generate .pro file more than once, only modify it when you add or remove cpp/ h files.

    Here is how it works:
    qmake is a Makefile generator. In your case, it creates an Xcode project file. Once you open that file in Xcode, it should work fine - with code completion and stuff. You should also be able to build and run the application from within Xcode. You should also expect some hurdles, especially since you don't know much about qmake and don't have experience with command line tools.



  • [quote author="sierdzio" date="1415640286"]I can't answer that with any degree of authority, because I've always tried to stay as far away from Xcode as possible; it's interface puts me off.

    Yes, I think (not sure!) you will need at least a main.cpp. But if you have more files with some project structure - even better. You do not need to generate .pro file more than once, only modify it when you add or remove cpp/ h files.

    Here is how it works:
    qmake is a Makefile generator. In your case, it creates an Xcode project file. Once you open that file in Xcode, it should work fine - with code completion and stuff. You should also be able to build and run the application from within Xcode. You should also expect some hurdles, especially since you don't know much about qmake and don't have experience with command line tools.[/quote]

    So i went ahead in got the Qt installed on my laptop. Now when i simply run the line:
    qmake -spec macx-xcode
    i get this:
    -bash: qmake: command not found

    So what will i do? Also what are the process to doing it all.
    Do i first create a Folder then create a main.cpp that contains this:

    #include <QApplication>
    #include <QPushButton>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QPushButton button("Ca marche !");
    button.show();
    return app.exec();
    }

    How do i get it all working? Sorry for the basic noob question, jsut trying to figure everything out !


  • Lifetime Qt Champion

    Hi,

    Use the full path to qmake. Qt's installation doesn't add it's bin path to the PATH environment variable which is a Good Thing(™). Sure it makes more to type to call qmake but it avoids silly mistakes when you have several Qt versions installed.



  • [quote author="SGaist" date="1415651202"]Hi,

    Use the full path to qmake. Qt's installation doesn't add it's bin path to the PATH environment variable which is a Good Thing(™). Sure it makes more to type to call qmake but it avoids silly mistakes when you have several Qt versions installed.[/quote]

    what do you mean by the full path environment?

    I was thinking of doing this:
    Step 3: Set the Environment variables
    In order to use Qt, some environment variables need to be extended.
    PATH - to locate qmake, moc and other Qt tools
    This is done like this:
    In .profile (if your shell is bash), add the following lines:
    PATH=/usr/local/Trolltech/Qt-4.8.6/bin:$PATH
    export PATH
    In .login (in case your shell is csh or tcsh), add the following line:
    setenv PATH /usr/local/Trolltech/Qt-4.8.6/bin:$PATH
    If you use a different shell, please modify your environment variables accordingly.
    That's all. Qt is now installed.

    But i was never able to find the .profile folder nor the usr/local/Trolltech folder.

    This is a bit confusing!


  • Lifetime Qt Champion

    Which version of Qt did you install ?



  • [quote author="SGaist" date="1415652772"]Which version of Qt did you install ?[/quote]

    Actually, i enable the hidden folder and managed to get .profile
    which i then added the environment variable.

    However, i cant find the folder TrollTech that the environment variable says.
    Also i'm using the latest Qt for Mac, since i just downloaded the dmg today and made sure i used the latest which i dont know by hear (above 5 surely)!
    I just installed it and thats it, i then got a Qt folder in the hard drive but i dont know were else to go with it? do i have to do this to fullfill the installation?

    http://qt-project.org/doc/qt-4.8/install-mac.html

    To configure the Qt library for your machine type, run the ./configure script in the package directory.
    By default, Qt is configured for installation in the /usr/local/Trolltech/Qt-4.8.6 directory, but this can be changed by using the -prefix option.
    cd /tmp/qt-everywhere-opensource-src-4.8.6
    ./configure
    Type ./configure -help to get a list of all available options.
    Note that you will need to specify -universal if you want to build universal binaries, and also supply a path to the -sdk option if your development machine has a PowerPC CPU. By default, Qt is built as a framework, but you can built it as a set of dynamic libraries (dylibs) by specifying the -no-framework option.
    Qt can also be configured to be built with debugging symbols. This process is described in detail in the Debugging Techniques document.
    To create the library and compile all the demos, examples, tools, and tutorials, type:
    make
    If -prefix is outside the build directory, you need to install the library, demos, examples, tools, and tutorials in the appropriate place. To do this, type:
    sudo make -j1 install
    This command requires that you have administrator access on your machine.
    Note: There is a potential race condition when running make install with multiple jobs. It is best to only run one make job (-j1) for the install.
    If you later need to reconfigure and rebuild Qt from the same location, ensure that all traces of the previous configuration are removed by entering the build directory and typing make confclean before running configure again.


  • Lifetime Qt Champion

    If you downloaded the latest Qt version it should be something like 5.3.X or 5.4 if you got the beta.

    You are following the 4.8 documentation, which is not completely valid for the 5.X series.

    Anyway, you can use Spotlight to find the exact position of qmake



  • [quote author="SGaist" date="1415656599"]If you downloaded the latest Qt version it should be something like 5.3.X or 5.4 if you got the beta.

    You are following the 4.8 documentation, which is not completely valid for the 5.X series.

    Anyway, you can use Spotlight to find the exact position of qmake[/quote]

    I have the 5.3 so what do i need to do? What do i personally need to follow to make sure that Qt is fully installed and ready to be used?

    Also i opened a terminal and "cd" to the folder that contains the main.cpp for the projects i want to use with Qt.

    When i do the qmake, i get the problem that its supposibly not working!

    What can i do?


  • Lifetime Qt Champion

    What I already wrote: call qmake with the absolute path to it e.g.

    @/usr/local/Qt/5.3.1/bin/qmake@

    Or something like that. You can easily find qmake using spotlight



  • [quote author="SGaist" date="1415752681"]What I already wrote: call qmake with the absolute path to it e.g.

    @/usr/local/Qt/5.3.1/bin/qmake@

    Or something like that. You can easily find qmake using spotlight[/quote]

    i get tons of qmake lol literally, i hate the Qt folder which has this:
    Qt > 5.3 >
    android_armv7
    clang_64
    ios
    Src

    Then each one of those folder have theyre own qmake, so in reality which one do i choose? i know i dont use ios or android since im building for desktop, so would i get clang or Src? Also if i choose src, what folder in Src do i choose? I have a bunch of folders starting with Qt....

    Sorry for all the dumb questions, i dont know about this and what might be simple for you guys might be a bit confusing for me! I appreciate all the help !

    So to clarify, i open up Terminal, then "sudo cd" into the directory were qmake is found in, correct? Once in there, i run the codes:
    qmake -project
    qmake -spec macx-xcode
    make

    However, my other question is, would i need to also insert the location of the folder were i'll be creating the program?


  • Moderators

    No need to use sudo. And you should cd into your project directory, not qmake dir. You should use qmake from clang_64 folder, like this:
    @
    cd /your/project/directory
    /Qt/5.3/clang_64/bin/qmake -project
    /Qt/5.3/clang_64/bin/qmake -spec macx-xcode
    make
    @



  • [quote author="sierdzio" date="1415775064"]No need to use sudo. And you should cd into your project directory, not qmake dir. You should use qmake from clang_64 folder, like this:
    @
    cd /your/project/directory
    /Qt/5.3/clang_64/bin/qmake -project
    /Qt/5.3/clang_64/bin/qmake -spec macx-xcode
    make
    @[/quote]

    Wow thats remarkably really straightforward lol, never knew that it was that simple! I guess i was simply been overwelmed by the tons of files!

    anyways when i call the qmake -project i get this error:

    Project ERROR: Could not resolve SDK path for 'macosx10.8'

    I'm guessing that Qt SDK is not properly linked to the macosx10.8, or what could it be specifically?



  • [quote author="sierdzio" date="1415775064"]No need to use sudo. And you should cd into your project directory, not qmake dir. You should use qmake from clang_64 folder, like this:
    @
    cd /your/project/directory
    /Qt/5.3/clang_64/bin/qmake -project
    /Qt/5.3/clang_64/bin/qmake -spec macx-xcode
    make
    @[/quote]

    Wow thats remarkably really straightforward lol, never knew that it was that simple! I guess i was simply been overwelmed by the tons of files!

    anyways when i call the qmake -project i get this error:

    Project ERROR: Could not resolve SDK path for 'macosx10.8'

    I'm guessing that Qt SDK is not properly linked to the macosx10.8, or what could it be specifically?


  • Moderators

    You're on Qt 4.8.6, right? It does not know about OS X 10.10, so I guess that is the problem. Check in Xcode, whether that SDK version is installed (and if it is still available at all).


  • Lifetime Qt Champion

    Qt's properly linked, the thing is that the latest version of Xcode doesn't provide that SDK anymore.

    IIRC, you only need to update the macx-clang mkspec to use the one you get with your version of Xcode



  • [quote author="SGaist" date="1415830510"]Qt's properly linked, the thing is that the latest version of Xcode doesn't provide that SDK anymore.

    IIRC, you only need to update the macx-clang mkspec to use the one you get with your version of Xcode[/quote]

    What do you mean? i have the latest Qt 5.3 sdk and xCode 6 so is there something i need to do specifically to be able to get what i need working already?


  • Moderators

    SGaist means you may need to modify macx-clang mkspecs (it's a folder inside Qt installation, which holds build configurations for different platforms) so that Qt knows about this new SDK.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.