[SOLVED]Using qmake basics



  • Hi guys.

    Someone can explain me, why qmake do this?:
    @
    quique@Quique-Lap:~/Qt/Examples/Qt-5.3/qmake/tutorial$ qmake -o Makefile hello.pro
    quique@Quique-Lap:~/Qt/Examples/Qt-5.3/qmake/tutorial$ make
    g++ -c -m64 -pipe -g -D_REENTRANT -Wall -W -fPIE -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o hello.o hello.cpp
    In file included from hello.cpp:42:0:
    hello.h:40:23: fatal error: QPushButton: No existe el archivo o el directorio
    #include <QPushButton>
    ^
    compilation terminated.
    make: *** [hello.o] Error 1
    quique@Quique-Lap:~/Qt/Examples/Qt-5.3/qmake/tutorial$
    @
    Thank you all.

    [andreyc EDIT]: Added @ around code



  • do you have Qt += core gui widgets ?


  • Moderators

    [quote author="Dheerendra" date="1410830730"]do you have Qt += core gui widgets ?[/quote]"core" and "gui" are available by default. You only need to add this line to your .pro file:

    @QT += widgets@

    Charlie_Hdz, since you are using Qt 5.3, have you thought of developing your project inside Qt Creator? It is easier that way, and you don't have to run qmake from the command line.



  • Thank you JKSH and that is true as well. Just wanted to recheck and there is not mistake. Also widgets is also added by default if Qt Widgets Project is created.



  • Thank you JKSH

    Im following a program that include a few examples of the use of qmake



  • When i just need compile a .cpp file with reference of Qt headers like QTextStream...How can i do it?

    i tried in terminal:

    g++ qtstreamdemo.cpp

    and then:

    qtstreamdemo.cpp:1:23: fatal error: QTextStream: No existe el archivo o el directorio
    #include <QTextStream>
    ^
    compilation terminated.


  • Lifetime Qt Champion

    You need to provide gcc with the include path to where QTextStream is located. Then you will also have to tell it where the libraries are located as well as link the them.



  • Ty SGaist

    Can you help me with a command example?


  • Lifetime Qt Champion

    That's basic g++

    @gcc -I/path/to/the/additional/includes -L/path/to/the/additional/libraries -lmylibrary mycppfile.cpp@

    Anyway, you should rather do something like

    @
    mkdir qtstreamdemo
    cd qtstreamdemo
    /* write qtstreamdemo.cpp */
    qmake -project
    qmake
    make
    @

    If you need additional Qt modules just edit the pro file to add them.

    Less complicated than writing all what is needed on the command line.



  • [quote author="SGaist" date="1410902182"]That's basic g++

    @gcc -I/path/to/the/additional/includes -L/path/to/the/additional/libraries -lmylibrary mycppfile.cpp@

    Anyway, you should rather do something like

    @
    mkdir qtstreamdemo
    cd qtstreamdemo
    /* write qtstreamdemo.cpp */
    qmake -project
    qmake
    make
    @

    If you need additional Qt modules just edit the pro file to add them.

    Less complicated than writing all what is needed on the command line.
    [/quote]

    Thanks a lot,its working, i did something like this:

    @
    mkdir qtstreamdemo
    cd qtstreamdemo
    //Create the .pro associated with Qt libraries (CONFIG += qt) and //the .cpp
    qmake -o Makefile qtstreamdemo.pro
    make
    ./qtstreamdemo
    @



  • Can you help me please?
    I tried to build this project:

    @
    TEMPLATE = app
    QT += widgets
    QT += core gui
    CONFIG += qt
    SOURCE += qtfirstapp.cpp
    TARGET = qtfirstapp

    SOURCES +=
    qtfirstapp.cpp

    @

    and the .cpp
    @

    #include <QtGui>

    int main(int argc,char* argv[]){
    QApplication app(argc,argv);
    QTextStream cout(stdout);

    //Declarations of variables
    int answer=0;
    do{
    //local variables to the loop:
    int factArg=0;
    int fact(1);
    factArg=QInputDialog::getInt(0,"Factorial Calculator","Factorial of: ",1); //Calls a template dialog of int inputs
    cout<<"User entered: "<<factArg<<endl;
    int i=2;

    //Here begins the calculation of Factorial of factArg
    while (i <= factArg){
      fact=fact*i;
      ++i;
    }
    
    QString response=QString("The factorial of %1 is %2. \n%3").arg(factArg).arg(fact)
     .arg("Compute another factorial?");
    answer=QMessageBox::question(0,"PlayAgain?",response,QMessageBox::Yes | QMessageBox::No);
    

    }while(answer == QMessageBox::Yes);

    return EXIT_SUCCESS;
    }

    @

    Using Qt Creator works fine, but in the Terminal make these errors:

    quique@Quique-Lap:~$ cd /home/quique/Escritorio/QtProjects/QtFirstApp
    quique@Quique-Lap:~/Escritorio/QtProjects/QtFirstApp$ qmake qtfirstapp.pro
    quique@Quique-Lap:~/Escritorio/QtProjects/QtFirstApp$ make
    g++ -c -m64 -pipe -O2 -D_REENTRANT -Wall -W -fPIE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I/usr/include/qt5 -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o qtfirstapp.o qtfirstapp.cpp
    qtfirstapp.cpp: In function ‘int main(int, char**)’:
    qtfirstapp.cpp:6:20: error: variable ‘QApplication app’ has initializer but incomplete type
    QApplication app(argc,argv);
    ^
    qtfirstapp.cpp:15:13: error: ‘QInputDialog’ has not been declared
    factArg=QInputDialog::getInt(0,"Factorial Calculator","Factorial of: ",1); //Calls a template dialog of int inputs
    ^
    qtfirstapp.cpp:27:12: error: ‘QMessageBox’ has not been declared
    answer=QMessageBox::question(0,"PlayAgain?",response,QMessageBox::Yes | QMessageBox::No);
    ^
    qtfirstapp.cpp:27:58: error: ‘QMessageBox’ has not been declared
    answer=QMessageBox::question(0,"PlayAgain?",response,QMessageBox::Yes | QMessageBox::No);
    ^
    qtfirstapp.cpp:27:77: error: ‘QMessageBox’ has not been declared
    answer=QMessageBox::question(0,"PlayAgain?",response,QMessageBox::Yes | QMessageBox::No);
    ^
    qtfirstapp.cpp:28:20: error: ‘QMessageBox’ has not been declared
    }while(answer == QMessageBox::Yes);
    ^
    make: *** [qtfirstapp.o] Error 1

    I guess is some command in the .pro but i dont know which is...
    Thank You


  • Moderators

    Hi,

    Error messages contain useful clues, so I recommend that you read them and try to remember what they mean. Most of your errors say '<Class>' has not been declared. That means you haven't #included their headers.

    You need to #include the header of each class that you use:
    @
    #include <QApplication>
    #include <QInputDialog>
    #include <QMessageBox>
    // etc.
    @

    I notice that you used #include <QtGui>. This worked in Qt 4, but it doesn't work in Qt 5.



  • Running...

    #include <QApplication>
    #include <QInputDialog>
    #include <QMessageBox>
    #include <iostream>
    #include <QTextStream>

    Thank you all


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.