Creating new project from existing files
[quote author="Gerolf" date="1299868515"]The command is:
I thought I'd leave looking that up as an excercise for the reader ;-)
sory, should I remove it, calling it censored?
Thanks, guys. I normally appreciate the value of exercises for the reader. If I don't get this code imported into Qt today, though, at least to where I can edit, build and do some rudimentary debugging, I may have to shelve Qt for the time and stay with the IDE that's currently giving me problems. So, for today anyway, product is more important than process.
So...is it OK if I build the project on top of a directory structure with subdirectories for source and includes? Or, is it better if I start with an empty project and import my files into it?
It is perfectly ok to start on top of the existing dir. But I personally would create a backup copy - just to be on the safe side.
Thanks, Volker. I guess what I'm trying to get at here is, there doesn't seem to be a traditional "import" function. I can create new files, or I can add existing files (but they don't "move" into the Qt directory structure). I was hoping that if I created my Qt project on top of an existing directory structure (which currently only contains two subdirectories), Qt would magically "discover" the files, but that doesn't seem to work, either.
It's a small enough number of files that I can just create new ones and cut and paste the contents from the old directory structure, but I was hoping there was a "smarter" way to do this.
That works as you expect it. Just cd into the toplevel directory of your project (that containing the two subdirs) and call
on the command line. This leaves a xxx.pro file in the dir, named after your directory. You can rename it it you want. qmake scans the dir recursively and puts all the header, implementation an UI files into the project file.
Then just open this .pro file in Creator and adjust all the settings.
OK, so...I hate to look like a thorough moron here, but...no use leaving things half-done.
I'm really inexperienced at command line stuff. I tried adding the path to the qmake program to my $PATH variable by adding this to my .bash_profile file:
@PATH="/Volumes/320 GB HD/Developer/Tools/Qt":$PATH
But it still says qmake's not found. I realize this isn't a Qt question, but can someone tell me what I'm doing wrong here?
I don't know the directory layout the prebuilt Qt packages for the Mac (I suppose this from the "/Volumes/" path :-) ), but it might be that you have to append /bin after the Qt.
No, the path name is good...in that directory is a file (actually a link) called qmake. I just realized, though, that the link points to a directory that isn't there (/usr/bin/qmake-4.7). Perhaps I'd better uninstall and reinstall Qt?
You might use spotlight to search for the location of qmake. It is available on the commandline too:
mdfind -name qmake
Thanks for the tip on mdfind.
The qmake file really doesn't seem to be there. I think I'd like to start over with Qt; what's the clean way to uninstall it?
[quote author="mzimmers" date="1299882964"]Thanks for the tip on mdfind.
The qmake file really doesn't seem to be there. I think I'd like to start over with Qt; what's the clean way to uninstall it?[/quote]
Sorry, I really don't know. I started with Qt at the Mac long before the binary packages and had to compile it manually, so I stick to this until now :-)
You might search the forum here, if I remember correctly, this was covered some time ago.
What's really strange is, that there is no qmake - it looks as if the setup did not install every piece correctly. Did you install the SDK or only the Qt libs (aka framework)?
And were you asked for an administrator password? Directory /usr/bin is root owned, even as user with admin privileges you must sudo to write to it.
I don't remember the details of when I installed it the first time. I know that I've been around this tree once before.
I'm just going to wipe out the directories, reinstall and hope for the best. I'll report back in a bit.
I now have a qmake program (and who knows what else), and the new project created successfully over the existing source directories.
Qt also logically collects the files in the directory into Headers and Sources, so my existing directories created a second, undesired level of indirection. I moved all the files into one directory and did it over, and it seems fine now. (I might say that it's just a tad undesirable for Qt to do that, as it would be nice if I could preserve an existing directory structure, but...I'm not in the mood for complaining.)
Thanks for all the help, guys. It does seem better to do it from the command line.
BTW: the -project switch for qmake is undocumented, at least when you type "qmake" in the terminal window.
Ahm... in my version (and every version I know of since Qt 3.0 times) mention the -project switch:
macbookpro ~ $ qmake
Usage: qmake [mode] [options] [files]
QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project
-project Put qmake into project file generation mode
In this mode qmake interprets files as files to
defaults to *.c; *.ui; *.y; *.l; *.ts; *.xlf; *.qrc; *.h; *.hpp; *.hh; *.hxx; *.H; *.cpp; *.cc; *.cxx; *.C
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-makefile Put qmake into makefile generation mode (default)
In this mode qmake interprets files as project files to
be processed, if skipped qmake will try to find a project
file in your current working directory
And of course there's always the famous
Oh, <insert curse word here>...
...burned by my lousy terminal scrolling ability. (Zimmers' 2nd rule of programming; blame as much as possible on the tools for your own foolishness.)
Thanks for the correction, Volker...now, if I can just get my build working (but I've started a new thread for that).
So...let me ask a related question, and this is more of style/convention than Qt usage.
If you have a relatively large project (say 100 source files), is it better to bring them into the workspace, or use the "Add Existing Files..." command?
The drawback as I see it to bringing the files into the workspace is that they're all in a flat file structure. I know Qt does a great job managing them for you from Creator, but...there are times when a developer may wish to access the project from the file system, and having everything in one directory doesn't make that easy.
So...is it better to add existing files and keep the workspace separate? The only drawback to this is that you get two levels of indirection: the one that Qt makes, and the one in your own directory structure. For example, I had a src subdirectory and a headers subdirectory, and they both appear under Sources and Headers, respectively, when I include them into the Qt project.
Thanks for any opinions on this.
For me, that would depend on the logical units you can decern in the design. I think it makes sense to devide big projects in logical units that are relatively independant, and who's sources you group. You can do that in Qt just as well. Where it makes sense you might even, instead of directly including the files in such a unit in the .pro file, include the files for such a unit in a .pri file, and include() that in your .pro file. That way, the files will even appear grouped in Qt Creator, and you can work with that group of file as a separate unit. I use this technique myself quite often.
If you study the source layout of Qt itself, you'll notice not everything is in a single there either...
I have my project organized in subdirs and divided in two qmake projects.
Qt Creator shows you the files organized by file type (Sources, Headers, UI, Resources, etc.) - it more or less relates to the .pro variables.
Under the file types, your files can be displayed according to the file system structure. Be sure to click on the icon !http://doc.qt.nokia.com/qtcreator-2.1/images/qtcreator-filter.png! and have "Simplify Tree" unchecked. See the "Qt Creator User Interface":http://doc.qt.nokia.com/qtcreator-2.1/creator-quick-tour.html docs for some more information.
Oh, OK...that's pretty slick. I think I'll delete my existing project and start over, with the files sorted into directories. Thanks.