Code examples from book "C++ GUI Programming with Qt4" are not recognized by Qt Creator
-
Ahm, no, that was created by the SDK. It's from September last year, though. Maybe the directory layout has changed since then.
You may want to open Terminal.app, got to the SDK folder in /Applications and run find:
@
cd /Applications/QtSDK
find . -name qmake
@This prints all occurences of a file called qmake relative to the SDK directory. Example output from my box is:
@
./Desktop/Qt/474/gcc/bin/qmake
./Examples/4.7/qmake
./Madde/madbin/qmake
./Madde/targets/harmattan-nokia-meego-api/bin/qmake
./Madde/tools/qt-tools_snow-leopard_2011-07-27_UnivBin_qt4.7.4-m0.22.11/bin/qmake
./Simulator/Qt/gcc/bin/qmake
@Ignore all the Madde, Simulator and Examples entries.
-
Opps, it looks like my post was added before yours. As I said I found it and works.
One more question though.
Does this mean that I wont be able to create a projects in Qt Creator paste code from the book and run it (something like the above code)? If this is true, can someone explain me why it does work with qmake but not in Qt creator?
-
[quote author="fs_tigre" date="1333716969"]Found it, awesome, it works.
/Applications//QtSDK/Desktop/Qt/4.8.0/gcc/bin/qmake -project
One more question though.
Does this mean that I wont be able to create a project in Qt Creator and run code from the book (something like the above code)? If this is true, can someone explain me why it does work with qmake but not in Qt creator?Thanks a lot for your help![/quote]
Ah, our answers overlapped - good to know it works now.
Qt Creator does not support running "qmake -project". You can create new Qt projects in Creator too, though. Usually you run one of the wizards
Hit Cmd-N for a new something...
choose Qt Widget Project on the left
choose Qt GUI application on the right
This will create a project and little, empty ui.
If you want to start from scratch, choose "Other Project" in step #2 and "Empty Qt project" in #3. You will have to add the Qt configuration and the source files you create afterwards to that file.
I usually prefer to create a Qt GUI project.
-
The way you described above is actually the way I have been using but I wanted to create everything myself and follow the book.
But what I dont know understand is why the following includes were not recognized in Qt Creator until I input the path in the terminal, they are now working but they were not before.
@#include <QApplication>
#include <QLabel>@Thanks
-
The book was written without knowledge of Qt Creator. It describes the steps for doing the stuff entirely on the command line.
Maybe you are better off using one of the Qt Creator tutorials?
-
i want to display more than one labels on same window , how could i do that ? i am trying somethong like this
but its opening two different windows ?
Please can any one explain me@
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QLabel>
#include <stdlib.h>int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
QLabel *label1 = new QLabel("qwerty!");
label1->show();
return app.exec();
}
@ -
ayushj it's recommended to create a new topic for each new question, and your question is not related to the original question.
Another recommendation related to your code, when you experiment with somethings do it in a small project separated from anything else, that way you can understand it easier.
Anyway, you can use layouts from code too, so to have two QLabels in an window you need a widget that will be the parent, an layout and those two labels:
@
#include <QApplication>
//#include "mainwindow.h"
#include <QLabel>
#include <QWidget>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget widget;//create the layout with the widget as parent
//(we use address of operator to get the address of widget)
QVBoxLayout* mainLayout = new QVBoxLayout(&widget);
QLabel *label = new QLabel("Hello Qt!");//label->show(); don't show them individually
QLabel *label1 = new QLabel("qwerty!");
//add the widgets to the layout:
mainLayout->addWidget(label);
mainLayout->addWidget(label1);//show the widget and that will show the children too
widget.show();
return app.exec();
}
@ -
i am trying to display labels (two labels one is "Hello qt" & "qwerty") on qt window (which is created qtwidget window ) one by one but it is showing three different windows with different labels first one is simple window which have nothing to display 2nd is label as "Hello Qt!" and 3rd as label "QWERTY"
i want to show this label on mainwindow one by one...............?
@#include <QLabel>
#include <stdlib.h>int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(320, 240);
QLabel *label = new QLabel("Hello Qt!");
label->show();
window.show();sleep(5);
QLabel *label1 = new QLabel("!QWERTY!");
label1->show();
return app.exec();
}@ -
Zlatomir thanks for your advice regarding the topic & objective,i will remember your recomendatons thanks much.
But, i think i am unable to explain my actual query to display labels "one by one" not in simultaneous manner.one by one means one label is first display then hide completely then second one come into the existent and it should be continous................is there any solutions related to what i am asking for ? Thanks much in advance -
[quote author="ayushj" date="1389158197"]But, i think i am unable to explain my actual query to display labels "one by one" not in simultaneous manner.one by one means one label is first display then hide completely then second one come into the existent and it should be continous................is there any solutions related to what i am asking for ?[/quote]You only need one QLabel. Update the text one by one using QLabel::setText().
Use "QTimer":http://qt-project.org/doc/qt-5/qtimer.html to trigger the updates.