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
/usr/local/Trolltech/Qt-4.4.1/include/QtGui
/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

Comments

  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?

    ReplyDelete
  2. try
    qmake -spec macx-g++ -macx file.pro

    ReplyDelete
  3. THANKS THANKS THANKS!!! :-)
    you saved me a lot of pain
    marco

    ReplyDelete
  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.

    thanks

    ReplyDelete
  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.

    Best
    -K

    ReplyDelete
  6. thanks, it works!

    ReplyDelete
  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.

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

    ReplyDelete

Post a Comment

Popular posts from this blog

A note on Python's __exit__() and errors

Python's context managers are a very neat way of handling code that needs a teardown once you are done. Python objects have do have a destructor method ( __del__ ) called right before the last instance of the object is about to be destroyed. You can do a teardown there. However there is a lot of fine print to the __del__ method. A cleaner way of doing tear-downs is through Python's context manager , manifested as the with keyword. class CrushMe: def __init__(self): self.f = open('test.txt', 'w') def foo(self, a, b): self.f.write(str(a - b)) def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.f.close() return True with CrushMe() as c: c.foo(2, 3) One thing that is important, and that got me just now, is error handling. I made the mistake of ignoring all those 'junk' arguments ( exc_type, exc_val, exc_tb ). I just skimmed the docs and what popped out is that you need to return True or...

Store numpy arrays in sqlite

Use numpy.getbuffer (or sqlite3.Binary ) in combination with numpy.frombuffer to lug numpy data in and out of the sqlite3 database: import sqlite3, numpy r1d = numpy.random.randn(10) con = sqlite3.connect(':memory:') con.execute("CREATE TABLE eye(id INTEGER PRIMARY KEY, desc TEXT, data BLOB)") con.execute("INSERT INTO eye(desc,data) VALUES(?,?)", ("1d", sqlite3.Binary(r1d))) con.execute("INSERT INTO eye(desc,data) VALUES(?,?)", ("1d", numpy.getbuffer(r1d))) res = con.execute("SELECT * FROM eye").fetchall() con.close() #res -> #[(1, u'1d', <read-write buffer ptr 0x10371b220, size 80 at 0x10371b1e0>), # (2, u'1d', <read-write buffer ptr 0x10371b190, size 80 at 0x10371b150>)] print r1d - numpy.frombuffer(res[0][2]) #->[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] print r1d - numpy.frombuffer(res[1][2]) #->[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] Note that for work where data ty...