tl;dr: Hello World the Qt5 way
OK.. Here's that famous program wrtitten for Qt 5, using the Qt Creator IDE. Except for the Xml, it's much simpler than the Win32 API version. And most of the code was created visually. And there's far more C++ code.
It's not as beautiful as the Win API (IMO), but it's practical (and probably powerful) so I'll explore it further. And it will work on Linux.
4 files:
//main.cpp: Main Program
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
-----------------------------------------------------------------------------------------------
//mainwindow.h: Main window class declaration
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
----------------------------------------------------------------------------------------
//mainwindow.cpp: Main window cclass definition
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
---------------------------------------------------------------------------------------------
//mainwindow.ui: User interface
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="StatusLabel">
<property name="geometry">
<rect>
<x>170</x>
<y>250</y>
<width>191</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>
Hello Pibbur</string>
</property>
<property name="textFormat">
<enum>Qt:
lainText</enum>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
protected: pibbuR
PS. Whatabout MFC? Mostly given up on that. It's old, as is most documentation. And VS support left something to be desired. Wizards worked (after changing a few settings). Building MFC applications from the ground up, which is the way I like to learn things caused linking problems (where is the cdecl __main function?). No help found when searching the net (admittedly I used Startpage in stead of Google, maybe Google could have found some). I finally got it working after installing VS 2015, using the exact same source code. I suppose I could have got it working on 2019 by adjusting more VS properties, but I couldn't find any info about what to change, and there are a lot of them!!! (Yes, I already had set MFC to be used as shared libraries). Got a bit fed up, and assuming that more problems would appear the further I went, I tried Qt, and haven't looked back. DS.
PPS: Thanks to the zloth for the emoji riddance tip . DS.