Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

I cannot compile a simple "hello" project



  • I have been programming for a number of years C/C++ and GUI with Windows forms. I am interested in learnig Qt4 and I downloaded the QtSDK 4.7.3 for OS X Lion (I have a Mac computer with this OS with Xcode.app 4.1). Following a "qmake Tutotrial" in the "qmake Manual" I set a "hello" project with the following files:

    "hello.h"
    #include <QPushButton>

    class MyPushButton : public QPushButton
    {
    public:
    MyPushButton(const QString &text;);
    };

    "hello.cpp"
    #include <QDebug>
    #include "hello.h"

    MyPushButton::MyPushButton(const QString &text;)
    : QPushButton(text)
    {
    setObjectName("mypushbutton");
    qDebug() << "My PushButton has been constructed";
    }

    "main.cpp"
    #include <QApplication>
    #include "hello.h"

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);

    MyPushButton helloButton("Hello world!");
    helloButton.resize(100, 30);
    
    helloButton.show();
    return app.exec();
    

    }

    I have created a"hello.pro" file
    CONFIG += qt
    HEDERS += hello.h
    SOURCES += hello.cpp
    SOURCES =+ main.cpp

    I have all these files in a subdirectory "Users/[my name]/Documents. Following the instructions of the tutorial I opened "Terminal" change to the directory where my files are and typed:
    qmake -o Makefile hello.pro.

    Terminal came back with:
    -bash: qmake: command not found

    I tried a number of different things with the same result. For example I found "qmake" in "Users/[my name]/QtSDK/Desktop/Qt/473/gcc/bin". I put a copy of "qmake" in the subdirectory with the other files with the same result. I also deleted the QtSDK and installed it again, rebooted my computer, etc.

    Then I tried something else; I opened Qt Creator.app (version 2.2.1) and I did "File->New File or Project->Other Project->Empty Qt Project". A called this project "hello", I set up as "Target" "Desktop". Then, within QT Creator I clicked on "Buil All" and I get an error message "No rule to make target 'hello.cpp' needed by 'hello.o". Stop.

    By the way I ran some of the examples in Qt Creator and the work correctly.

    I will appreciate any ideas about compiling this project.



  • Hi mcII,

    Welcome to the devnet forum!

    Could put your code in @ tags or use the button with <> on it on top of this editor? That makes it more readable.

    You could also make a new project based on this "tutorial":http://doc.qt.nokia.com/4.7/gettingstartedqt.html. I'm not sure which qmake tutorial you used. Could be an old one. Since you are a GUI guy i think you like it better ;)

    Did you use the general console ? You should use the one you can find in the Qt group, which has all the needed paths set in. Go to start > Qt > ...console (or something like that)



  • Try this "tutorial":http://doc.qt.nokia.com/4.7-snapshot/install-mac.html. You need to set the environment variables, because your console right now knows nothing about where to find qmake and qt libs.



  • Some mistakes when writing pro file
    @
    HEDERS += hello.h
    SOURCES += hello.cpp
    SOURCES =+ main.cpp
    @

    to

    @
    HEADERS += hello.h
    SOURCES += hello.cpp
    main.cpp
    @

    Maybe still have some problem, i think you should try some example code first :D



  • [quote author="Chuck Gao" date="1312040115"]Some mistakes when writing pro file
    @
    HEDERS += hello.h
    SOURCES += hello.cpp
    SOURCES =+ main.cpp
    @
    [/quote]

    I think mcII sealed when post this, because he would have caught the error at compile time.
    Although what I'm saying he's not yet compiled :-D



  • Thank you for your help. My background is from the "old" school of MS DOS but so far I have very little knowledge of the equivalent in the Mac world. I have no clue about setting environment variables in Mac I don't want to use this forum to learn these basics.
    I will look for books where I can learn as much as I need of the Mac Terminal. If after my education effort I have problems, I will come to this forum for help. Thanks again.



  • [quote author="mcII" date="1312043464"]Thank you for your help. My background is from the "old" school of MS DOS but so far I have very little knowledge of the equivalent in the Mac world. I have no clue about setting environment variables in Mac I don't want to use this forum to learn these basics.
    I will look for books where I can learn as much as I need of the Mac Terminal. If after my education effort I have problems, I will come to this forum for help. Thanks again.[/quote]

    Everything is fine, this forum was created for this purpose and you can ask about all.


Log in to reply