C Please help me with Qt issues

I am new to Qt and I am confused as to how this works, please forgive me if this is a stupid question so here it is.

I am running FreeBSD 13.0 and install all necessary packages for Qt 5 and I created a simple that found on the newly purchased book C++ GUI Programming with QT4 (Old) but I wanted to cover the basics


Code:
#include <QApplication>
#include <QLabel>





int main(int argc, char *argv[])


{


    QApplication app(argc, argv);

    QLabel hello("<center>Welcome to my first Qt program. Be the best!!!</center>");

    hello.setWindowTitle("My First Qt Program");

    hello.resize(400, 400);


    hello.show();

    return app.exec();



}


and when I compiled the code using $make I get a" fatal error 'QApplication' file not found. Below is my version of qmake

Code:
$qmake -v

QMAKE version 3.0
Using Qt version 5.15.2 in /usr/local/lib/qt5

although I compiled the program with an error using "make" I still get an executable program which leads me to the next question guys. Qt program runs fine on FreeBSD but; when I copy the executable file to Linux Debian and Windows 10 and tried to execute the file but it did not run... What gives????... I thought Qt was a multi-platform, am I wrong? or am I doing it wrong? " Please forgive me if this is a stupid question like I said I am new to Qt and I want to create applications that are multi cross-platform that can run on Linux, Windows, and Unix.
 
The question is not stupid. I also fail to compile to most basic hello world in qt5 for several reasons.
Or the tutorial is for Windows, or the tutorial is for qt4 or the tutorial uses the moronic qtdesigner-gui.
I wonder if you must use clang or gcc and which version.
 
Ok, i have a working hello world compiled for qt5.
But it's better i don't share it because it was ugly like copying header files and removing c lines which produced errors.
Hello world should compile without any error or hack. But how ?
 
Note : #include <QApplication> is for windows i think.
On freebsd you have to use :
Code:
#include <qapplication.h>
The location of the file is :
Code:
/usr/local/include/qt5/QtWidgets/qapplication.h
 
First if you are interested in Qt development I would recommend you to install devel/qtcreator

Programs compiled for FreeBSD won't run on Linux or Windows an viceversa, when they say that Qt is multiplatform it means that the code can be compiled for other platforms. For example you can install the Qt SDK on Windows and then open your code and compile it there with minimal changes if any.

Edit: Also maybe you're missing widgets in the .pro file specially if the example was made for Qt4

Code:
QT += widgets
 
First if you are interested in Qt development I would recommend you to install devel/qtcreator

Programs compiled for FreeBSD won't run on Linux or Windows an viceversa, when they say that Qt is multiplatform it means that the code can be compiled for other platforms. For example you can install the Qt SDK on Windows and then open your code and compile it there with minimal changes if any.

Edit: Also maybe you're missing widgets in the .pro file specially if the example was made for Qt4

Code:
QT += widgets
I do have
Code:
 QT += widgets

on my file *.pro
 
For developing a cross-platform gui i would personally use dlang+gtkd.
Below a thread about a question i've posted,
 
Just chiming in - QT v.5 is no longer maintained. The KDE project keeps using an archive copy (v. 5.15.2) for Frameworks 5.70, 5.71, 5.72, and so on, while they wait for QT6 to become stable. There's nothing wrong with using an older version of QT to learn how to use an API toolkit and how to troubleshoot the errors in the code - Just realize that the term 'Cross-platform' is does not always mean what you expect it to mean.

FWIW, truly cross-platform language would have to be HTML5. Java was touted as 'Cross Platform' when I was in college - but that came with a big if - the 'if' being that you have to have a copy of Java Virtual Machine installed if you compile a Java binary on Linux, and want to run it on Windows... Criosphinx provided one good example of what 'Cross-platform' means in case of QT - that is just another attempt at making code 'cross platform'. Even that requires a bit of extra effort for every new platform you copy the compiled code to. There's no magic bullet here.
 
Just chiming in - QT v.5 is no longer maintained. The KDE project keeps using an archive copy (v. 5.15.2) for Frameworks 5.70, 5.71, 5.72, and so on, while they wait for QT6 to become stable. There's nothing wrong with using an older version of QT to learn how to use an API toolkit and how to troubleshoot the errors in the code - Just realize that the term 'Cross-platform' is does not always mean what you expect it to mean.

FWIW, truly cross-platform language would have to be HTML5. Java was touted as 'Cross Platform' when I was in college - but that came with a big if - the 'if' being that you have to have a copy of Java Virtual Machine installed if you compile a Java binary on Linux, and want to run it on Windows... Criosphinx provided one good example of what 'Cross-platform' means in case of QT - that is just another attempt at making code 'cross platform'. Even that requires a bit of extra effort for every new platform you copy the compiled code to. There's no magic bullet here.


Thank you very much!!!!
 
For developing a cross-platform gui i would personally use dlang+gtkd.
Below a thread about a question i've posted,
Thank you
 
okay understood, Now. Will my compiled executable Qt program will work on another FreeBSD box? without installing any additional packages on the other FreeBSD box.


Making my own notes so all my Qt compiled programs within FreeBSD will only run on FreeBSD.
 

Attachments

  • Qt.png
    Qt.png
    16.5 KB · Views: 134
Gui programs mostly use shared libraries and that is software that needs to be available on the freebsd computer to run.
If it's "additional" or already "available" for that computer depends. Some users install many packages , some install few packages.
Code:
ldd ./my_qt5_hello_world
shows
Code:
    libQt5Widgets.so.5 => /usr/local/lib/qt5/libQt5Widgets.so.5 (0x800400000)
    libQt5Gui.so.5 => /usr/local/lib/qt5/libQt5Gui.so.5 (0x800aa4000)
    libQt5Core.so.5 => /usr/local/lib/qt5/libQt5Core.so.5 (0x801200000)
    libGL.so.1 => /usr/local/lib/libGL.so.1 (0x800249000)
    libc++.so.1 => /usr/lib/libc++.so.1 (0x8002e0000)
    libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x8003b4000)
    libm.so.5 => /lib/libm.so.5 (0x801105000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x8003d7000)
    libthr.so.3 => /lib/libthr.so.3 (0x801136000)
    libc.so.7 => /lib/libc.so.7 (0x80174d000)
    libpng16.so.16 => /usr/local/lib/libpng16.so.16 (0x801163000)
    libz.so.6 => /lib/libz.so.6 (0x8011a1000)
    libharfbuzz.so.0 => /usr/local/lib/libharfbuzz.so.0 (0x801b61000)
    libkvm.so.7 => /lib/libkvm.so.7 (0x8011be000)
    libprocstat.so.1 => /usr/lib/libprocstat.so.1 (0x8003f1000)
    libexecinfo.so.1 => /usr/lib/libexecinfo.so.1 (0x8011d3000)
    libdouble-conversion.so.3 => /usr/local/lib/libdouble-conversion.so.3 (0x8011d9000)
    libicui18n.so.68 => /usr/local/lib/libicui18n.so.68 (0x801c4c000)
    libicuuc.so.68 => /usr/local/lib/libicuuc.so.68 (0x801f8f000)
    libpcre2-16.so.0 => /usr/local/lib/libpcre2-16.so.0 (0x802199000)
    libzstd.so.1 => /usr/local/lib/libzstd.so.1 (0x802242000)
    libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x802341000)
    libglapi.so.0 => /usr/local/lib/libglapi.so.0 (0x802479000)
    libdrm.so.2 => /usr/local/lib/libdrm.so.2 (0x8024e5000)
    libX11.so.6 => /usr/local/lib/libX11.so.6 (0x8024fd000)
    libxcb-glx.so.0 => /usr/local/lib/libxcb-glx.so.0 (0x80264b000)
    libxcb.so.1 => /usr/local/lib/libxcb.so.1 (0x802669000)
    libX11-xcb.so.1 => /usr/local/lib/libX11-xcb.so.1 (0x8011ee000)
    libxcb-dri2.so.0 => /usr/local/lib/libxcb-dri2.so.0 (0x8011f2000)
    libXext.so.6 => /usr/local/lib/libXext.so.6 (0x802696000)
    libXfixes.so.3 => /usr/local/lib/libXfixes.so.3 (0x8026ab000)
    libXdamage.so.1 => /usr/local/lib/libXdamage.so.1 (0x8011f9000)
    libXxf86vm.so.1 => /usr/local/lib/libXxf86vm.so.1 (0x8026b3000)
    libexpat.so.1 => /usr/local/lib/libexpat.so.1 (0x8026bb000)
    libxcb-dri3.so.0 => /usr/local/lib/libxcb-dri3.so.0 (0x8026ec000)
    libxcb-present.so.0 => /usr/local/lib/libxcb-present.so.0 (0x8026f3000)
    libxcb-sync.so.1 => /usr/local/lib/libxcb-sync.so.1 (0x8026f8000)
    libxshmfence.so.1 => /usr/local/lib/libxshmfence.so.1 (0x802701000)
    libxcb-xfixes.so.0 => /usr/local/lib/libxcb-xfixes.so.0 (0x802706000)
    libfreetype.so.6 => /usr/local/lib/libfreetype.so.6 (0x802710000)
    libgraphite2.so.3 => /usr/local/lib/libgraphite2.so.3 (0x8027d7000)
    libelf.so.2 => /lib/libelf.so.2 (0x802804000)
    libutil.so.9 => /lib/libutil.so.9 (0x802820000)
    libicudata.so.68 => /usr/local/lib/libicudata.so.68 (0x802837000)
    libpcre.so.1 => /usr/local/lib/libpcre.so.1 (0x80283a000)
    libintl.so.8 => /usr/local/lib/libintl.so.8 (0x8028dd000)
    libiconv.so.2 => /usr/local/lib/libiconv.so.2 (0x8028ec000)
    libXau.so.6 => /usr/local/lib/libXau.so.6 (0x8029eb000)
    libXdmcp.so.6 => /usr/local/lib/libXdmcp.so.6 (0x8029f1000)
    libbz2.so.4 => /usr/lib/libbz2.so.4 (0x8029f9000)
    libbrotlidec.so.1 => /usr/local/lib/libbrotlidec.so.1 (0x802a11000)
    libbrotlicommon.so.1 => /usr/local/lib/libbrotlicommon.so.1 (0x802a20000)
 
Gui programs mostly use shared libraries and that is software that needs to be available on the freebsd computer to run.
If it's "additional" or already "available" for that computer depends. Some users install many packages , some install few packages.
Code:
ldd ./my_qt5_hello_world
shows
Code:
    libQt5Widgets.so.5 => /usr/local/lib/qt5/libQt5Widgets.so.5 (0x800400000)
    libQt5Gui.so.5 => /usr/local/lib/qt5/libQt5Gui.so.5 (0x800aa4000)
    libQt5Core.so.5 => /usr/local/lib/qt5/libQt5Core.so.5 (0x801200000)
    libGL.so.1 => /usr/local/lib/libGL.so.1 (0x800249000)
    libc++.so.1 => /usr/lib/libc++.so.1 (0x8002e0000)
    libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x8003b4000)
    libm.so.5 => /lib/libm.so.5 (0x801105000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x8003d7000)
    libthr.so.3 => /lib/libthr.so.3 (0x801136000)
    libc.so.7 => /lib/libc.so.7 (0x80174d000)
    libpng16.so.16 => /usr/local/lib/libpng16.so.16 (0x801163000)
    libz.so.6 => /lib/libz.so.6 (0x8011a1000)
    libharfbuzz.so.0 => /usr/local/lib/libharfbuzz.so.0 (0x801b61000)
    libkvm.so.7 => /lib/libkvm.so.7 (0x8011be000)
    libprocstat.so.1 => /usr/lib/libprocstat.so.1 (0x8003f1000)
    libexecinfo.so.1 => /usr/lib/libexecinfo.so.1 (0x8011d3000)
    libdouble-conversion.so.3 => /usr/local/lib/libdouble-conversion.so.3 (0x8011d9000)
    libicui18n.so.68 => /usr/local/lib/libicui18n.so.68 (0x801c4c000)
    libicuuc.so.68 => /usr/local/lib/libicuuc.so.68 (0x801f8f000)
    libpcre2-16.so.0 => /usr/local/lib/libpcre2-16.so.0 (0x802199000)
    libzstd.so.1 => /usr/local/lib/libzstd.so.1 (0x802242000)
    libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x802341000)
    libglapi.so.0 => /usr/local/lib/libglapi.so.0 (0x802479000)
    libdrm.so.2 => /usr/local/lib/libdrm.so.2 (0x8024e5000)
    libX11.so.6 => /usr/local/lib/libX11.so.6 (0x8024fd000)
    libxcb-glx.so.0 => /usr/local/lib/libxcb-glx.so.0 (0x80264b000)
    libxcb.so.1 => /usr/local/lib/libxcb.so.1 (0x802669000)
    libX11-xcb.so.1 => /usr/local/lib/libX11-xcb.so.1 (0x8011ee000)
    libxcb-dri2.so.0 => /usr/local/lib/libxcb-dri2.so.0 (0x8011f2000)
    libXext.so.6 => /usr/local/lib/libXext.so.6 (0x802696000)
    libXfixes.so.3 => /usr/local/lib/libXfixes.so.3 (0x8026ab000)
    libXdamage.so.1 => /usr/local/lib/libXdamage.so.1 (0x8011f9000)
    libXxf86vm.so.1 => /usr/local/lib/libXxf86vm.so.1 (0x8026b3000)
    libexpat.so.1 => /usr/local/lib/libexpat.so.1 (0x8026bb000)
    libxcb-dri3.so.0 => /usr/local/lib/libxcb-dri3.so.0 (0x8026ec000)
    libxcb-present.so.0 => /usr/local/lib/libxcb-present.so.0 (0x8026f3000)
    libxcb-sync.so.1 => /usr/local/lib/libxcb-sync.so.1 (0x8026f8000)
    libxshmfence.so.1 => /usr/local/lib/libxshmfence.so.1 (0x802701000)
    libxcb-xfixes.so.0 => /usr/local/lib/libxcb-xfixes.so.0 (0x802706000)
    libfreetype.so.6 => /usr/local/lib/libfreetype.so.6 (0x802710000)
    libgraphite2.so.3 => /usr/local/lib/libgraphite2.so.3 (0x8027d7000)
    libelf.so.2 => /lib/libelf.so.2 (0x802804000)
    libutil.so.9 => /lib/libutil.so.9 (0x802820000)
    libicudata.so.68 => /usr/local/lib/libicudata.so.68 (0x802837000)
    libpcre.so.1 => /usr/local/lib/libpcre.so.1 (0x80283a000)
    libintl.so.8 => /usr/local/lib/libintl.so.8 (0x8028dd000)
    libiconv.so.2 => /usr/local/lib/libiconv.so.2 (0x8028ec000)
    libXau.so.6 => /usr/local/lib/libXau.so.6 (0x8029eb000)
    libXdmcp.so.6 => /usr/local/lib/libXdmcp.so.6 (0x8029f1000)
    libbz2.so.4 => /usr/lib/libbz2.so.4 (0x8029f9000)
    libbrotlidec.so.1 => /usr/local/lib/libbrotlidec.so.1 (0x802a11000)
    libbrotlicommon.so.1 => /usr/local/lib/libbrotlicommon.so.1 (0x802a20000)
Understood. Thank you for all the information.
 
On FreeBSD (and Linux, FWIW), programs generally have 'runtime' dependencies. For example, a simple QT program really depends on having Xorg (or Wayland) installed first, and a load of compiled QT libraries. Alain De Vos provided a nice long list of those runtime dependencies. If any of that is missing, the QT program won't run. So if you compile a QT-based helloworld and copy that to a FreeBSD system that does not have all of the runtime deps installed, your program won't run.

Simple userland utilities like /bin/grep only require that the FreeBSD kernel is installed and booted. Those can generally be copied - but even then, you have to pay attention to kernel versions - 13.0-RELEASE won't run a copy of /bin/grep that has been ripped out of a system with 6.0-RELEASE. Difference is incompatible ABI (Application Binary Interface, not to be confused with API, Application Programming Interface)
 
Back
Top