User Tools

Site Tools


programming:qt

Qt

Get Qt from https://www.qt.io/download. The main programs you are interested in are the QtCreator which is the IDE and the Designer which is the UI builder (usually integrated right into QtCreator already though).

For Qt in Python, see PyQt5 Tutorial

Installation

In Debian, install Qt5 libraries, QtCreator IDE and UI Designer with apt install qt5-default qtcreator. Run the IDE with qtcreator. Run the GUI Designer with designer.

qDebug verbosity levels

Qt has multiple levels of verbosity for logging. If you are able to print qInfo() messages but qDebug() is not outputting anything, you need to turn on the debug messages.

qdebug_example.cpp
#include <QDebug>
 
// ...
 
qInfo() << "Is this working?";
qDebug() << "but not this?";

You can set the Qt logging levels in ~/.config/QtProject/qtlogging.ini like this:

qtlogging.ini
# ~/.config/QtProject/qtlogging.ini
[Rules]
*.debug=true  # Enable all debug messages
qt.*.debug=false  # Disable qt debug messages, leaving only ours

Using WinPcap with Qt

qt5_winpcap.cpp
// If using qt creator, add these
// to the project file in Windows
// 
//# Pcap specific build stuff for Windows (in qmake)
//INCLUDEPATH += C:/WpdPack/Include
//LIBS += C:/WpdPack/Lib/wpcap.lib
//LIBS += C:/WpdPack/Lib/Packet.lib
//CONFIG += no_lflags_merge
//
//# Fixes the missing inet_to_ntoa
//LIBS += -lws2_32
 
 
 
#define HAVE_REMOTE
#include <winsock2.h>
#include "pcap.h"
 
/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header, const u_char *pkt_data);
 
int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];
 
    /* Retrieve the device list on the local machine */
    if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
    {
        fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
        exit(1);
    }
 
    /* Print the list */
    for(d=alldevs; d; d=d->next)
    {
        printf("%d. %s", ++i, d->name);
        if (d->description)
            printf(" (%s)\n", d->description);
        else
            printf(" (No description available)\n");
    }
 
    if(i==0)
    {
        printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
        return -1;
    }
}
programming/qt.txt · Last modified: 2021/06/11 05:52 by nanodano