Skip to main content

Setting up a C++/QT project on eclipse under Mac OS X

The compile steps with Qt4 are:
  1. qmake -project [generates a .pro file based on the files you have in the root directory]
  2. qmake [genrates the Makefile from the .pro file]
  3. make [gnu make that uses the Makefile to generate your project as a *.app folder]
To get eclipse to follow this chain I did
  1. Fire up eclipse and choose File->New->C++ Project
  2. Uncheck 'use default location' and browse to the root of your code tree
  3. Enter a Project name e.g. ChhobiQT
  4. Pick Empty Project (leave MavOSX GCC as is)
    At this stage eclipse will find your files/subdirectories and try and compile and probably give you an error. Ignore this smart ass behavior or uncheck Project->Build automatically
  5. Project->Properties (If this is grayed out, make sure to click and highlight ChhobiQT)
  6. ->C/C++ Build : Uncheck 'Generate Makefiles automatically'
  7. 'Build directory' set it to the variable ${project_loc}
  8. Run->External Tools Dialog
  9. Under program create a new entry and set:
    Name : qmake1
    Location : location of qmake on your system e.g. /usr/local/Trolltech/Qt-4.4.0/bin/qmake
    Working directory : ${project_loc}
    Arguments : -project
    This 'External program' will enable you to generate a *.pro file when you need it
  10. Make an identical entry but name is qmake2 and make Arguments blank
    This entry will let you generate a Makefile when you add files to the project
  11. Now click Run->External Tools->qmake1 and then qmake2
  12. Hit F5 to refresh the Project explorer
    You should see a .pro file and a Makefile
  13. Project->Build Project
    You should now have a *.app file
  14. Run->Run
    Your application should now run
Each time you add a new file to the configuration you need to rerun qmake -project and qmake.

Note on Code Completion:
Go to Project->Properties->C/C++ General->Paths and Symbols
In the GNU C++ tab add the following paths (depending on the version of QT)
/usr/local/Trolltech/Qt-4.4.1/include/QtSql (if you use sql)

The rebuild code index
This will take care of code competion and things like Q_OBJECT being not recognized


  1. I'm just tinkering with Qt for the Mac. I'm having some trouble... qmake does not generate a makefile; instead it generates a .xcodeproj file. Any clues on how I can get it to use Makefiles under MacOS X?

  2. try
    qmake -spec macx-g++ -macx

    you saved me a lot of pain

  4. Hi.

    I have followed your steps and I get a working .app file and the app works fine. BUT I don't get code completion in Eclipse. I have no error highlights but some q_object highlights.

    Any Ideas?

    Using cdt 5.0.2.


  5. Hi,

    I'm assuming you did the last step at the end. You will have to tailor the paths to your local install of QT. And (**this is important**) QT should be compiled with symbols on. For some reason the actual install of QT I use 4.4.4 does not work, I link to an older version 4.4.1 I forget exactly what it is, but I think you have to **configure as debug** which generates symbol tables. I don't know enough about the internals to explain the mechanism.


  6. thanks, it works!

  7. HI,

    First of all thanks for creating this helpful document.

    I have follow your steps but when qmake1 command to create .pro file i found the below error.

    ERROR :
    make: *** No rule to make target `all'. Stop.

    While someone please guid me to solve this issue.

  8. This is the first tutorial that actually works. Under Linux too. Thanks!


Post a Comment

Popular posts from this blog

Python: Multiprocessing: passing multiple arguments to a function

Write a wrapper function to unpack the arguments before calling the real function. Lambda won't work, for some strange un-Pythonic reason.

import multiprocessing as mp def myfun(a,b): print a + b def mf_wrap(args): return myfun(*args) p = mp.Pool(4) fl = [(a,b) for a in range(3) for b in range(2)] #mf_wrap = lambda args: myfun(*args) -> this sucker, though more pythonic and compact, won't work, fl)

Flowing text in inkscape (Poster making)

You can flow text into arbitrary shapes in inkscape. (From a hint here).

You simply create a text box, type your text into it, create a frame with some drawing tool, select both the text box and the frame (click and shift) and then go to text->flow into frame.


The omnipresent anonymous asked:
Trying to enter sentence so that text forms the number three...any ideas?
The solution:
Type '3' using the text toolConvert to path using object->pathSize as necessaryRemove fillUngroupType in actual text in new text boxSelect the text and the '3' pathFlow the text

Running a task in a separate thread in a Tkinter app.

Use Queues to communicate between main thread and sub-threadUse wm_protocol/protocol to handle quit eventUse Event to pass a message to sub-threadimport Tkinter as tki, threading, Queue, time def thread(q, stop_event): """q is a Queue object, stop_event is an Event. stop_event from """ while(not stop_event.is_set()): if q.empty(): q.put(time.strftime('%H:%M:%S')) class App(object): def __init__(self): self.root = tki.Tk() = tki.Text(self.root, undo=True, width=10, height=1)'left') self.queue = Queue.Queue(maxsize=1) self.poll_thread_stop_event = threading.Event() self.poll_thread = threading.Thread(target=thread, name='Thread', args=(self.queue,self.poll_thread_stop_event)) self.poll_thread.start() self.poll_interval = 250 self.poll() self.root.wm_protocol("WM_DELETE…