Showing posts with label Qt5. Show all posts
Showing posts with label Qt5. Show all posts

Sunday, February 7, 2016

Qt5 Hello World on CentOS from command line with gcc

Install the libraries (I assume you have already installed gcc 4.8.x & friends on your system):
The Qt5 (pronounced as cute-five) base components

sudo yum install qt5-qtbase* 
sudo yum install mesa-libGL-devel -y
 
 
Create your project's folder: 
 
>>mkdir hello_world_qt
>>cd hello_world_qt 
 
 
Write hello word C++ file:
 
 
>> vi hello_world_qt.cpp
 
with content: 
 
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
 
int main(int argc, char **argv)
{
 QApplication app (argc, argv);
 
 QPushButton button ("Hello world !");
 button.show();
 
 return app.exec();
}
 
 
then make a qt project with qmake:
 
>>qmake-qt5 -project
 
 
edit the *new* file hello_world_qt.pro by adding the line QT += widgets before TEMPLATE. The final file will look similar to this:
 
 
######################################################################
# Automatically generated by qmake (3.0) Sun Feb 7 15:13:47 2016
######################################################################

QT += widgets

TEMPLATE = app
TARGET = hello2
INCLUDEPATH += .

# Input
SOURCES += hello_world_qt.cpp
 
 
Now generate the Makefile with qmake:
 
>>qmake-qt5 -makefile
 
 
Finally, you can compile your program:
 
 
>>make 
  
 
and run it!
 
>>./hello_world_qt
 
 
 
 
 
------------------------------------------------------- 
NOTE: I ended up with this solution because I got the errors below (missing libraries) 

/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:20: undefined reference to `QApplication::QApplication(int&, char**, int)'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:22: undefined reference to `QPushButton::QPushButton(QString const&, QWidget*)'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:23: undefined reference to `QWidget::show()'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:25: undefined reference to `QApplication::exec()'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:22: undefined reference to `QPushButton::~QPushButton()'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:25: undefined reference to `QApplication::~QApplication()'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:25: undefined reference to `QApplication::~QApplication()'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:22: undefined reference to `QPushButton::~QPushButton()'
/home/eddie/QT_HOME/hello_world_qt/hello_world_qt.cpp:22: undefined reference to `QPushButton::~QPushButton()'
collect2: error: ld returned 1 exit status 
 
  
Sources for this post:
https://csl.name/post/qt-gcc/
http://stackoverflow.com/