Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.3k Topics 456.0k Posts
  • QtWidgets/QAction: No such file or directory

    Unsolved
    5
    0 Votes
    5 Posts
    4k Views
    A
    Try deleting the ui_*.h file and try again
  • redditclient - missing Platform Plugin?

    Unsolved
    8
    0 Votes
    8 Posts
    1k Views
    TrinitronXT
    For those in the future stumbling across this by searching for the error: $ speedcrunch kf.windowsystem: Could not find any platform plugin I managed to solve this on Manjaro Linux by installing the kwayland-integration package. Other distros can probably install the appropriate package, built from this git repo. Other Wayland-related packages & env vars that I needed: Packages: qt5-wayland, qt6-wayland kwayland5 kvantum-qt5 qt5ct Environment Variables: QT Wayland: QT_QPA_PLATFORM="wayland" QT_QPA_PLATFORMTHEME=qt5ct QT_WAYLAND_DISABLE_WINDOWDECORATION="1" Sway / XDG Base Specification: XDG_CONFIG_HOME=${HOME}/.config WAYLAND_DISPLAY=wayland-1 XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=sway XDG_RUNTIME_DIR=/run/user/1000 XDG_DATA_DIRS=${HOME}/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share/:/usr/share/
  • How to Accurately Determine What State I'm In’ Using Qt and Navigation APIs?

    Unsolved
    2
    0 Votes
    2 Posts
    135 Views
    Pl45m4P
    @shohre said in How to Accurately Determine What State I'm In’ Using Qt and Navigation APIs?: My question is focused on the best practices and available tools within the Qt framework that can facilitate this kind of geolocation translation Check Qt's Geolocation and Positioning Module out https://doc.qt.io/qt-6/qtpositioning-index.html When using QML, you can use MapView to show retrieved points on an OpenStreetMap-based map. https://doc.qt.io/qt-6/qtlocation-mapviewer-example.html
  • Expand printed area in a PDF

    Unsolved
    26
    0 Votes
    26 Posts
    2k Views
    artwawA
    It's mostly generic. CMakeLists: cmake_minimum_required(VERSION 3.5) project(qpdWriterTest VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) set(PROJECT_SOURCES main.cpp mainwindow.cpp mainwindow.h mainwindow.ui ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(qpdWriterTest MANUAL_FINALIZATION ${PROJECT_SOURCES} res.qrc ) # Define target properties for Android with Qt 6 as: # set_property(TARGET qpdWriterTest APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(qpdWriterTest SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(qpdWriterTest ${PROJECT_SOURCES} ) endif() endif() target_link_libraries(qpdWriterTest PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. if(${QT_VERSION} VERSION_LESS 6.1.0) set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.qpdWriterTest) endif() set_target_properties(qpdWriterTest PROPERTIES ${BUNDLE_ID_OPTION} MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) include(GNUInstallDirs) install(TARGETS qpdWriterTest BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(qpdWriterTest) endif() main.cpp #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QTextDocument> 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; QTextDocument txt; private slots: void render(); }; #endif // MAINWINDOW_H mainwindow.cpp #include "mainwindow.h" #include "./ui_mainwindow.h" #include <QFile> #include <QPdfWriter> #include <QPainter> #include <QStandardPaths> #include <QTextCursor> #include <QTextTable> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); QFile f(":/test.html"); f.open(QIODevice::ReadOnly); txt.setHtml(f.readAll()); f.close(); connect(ui->pushButton,&QPushButton::clicked,this,&MainWindow::render); txt.setPageSize(QPageSize(QPageSize::A4).sizePoints()); txt.setDocumentMargin(0); } MainWindow::~MainWindow() { delete ui; } void MainWindow::render() { QString filePath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); QPdfWriter pdfWriter(filePath+"/test.pdf"); QImage img(":/Logo.png"); txt.addResource(QTextDocument::ImageResource, QUrl("Logo.png"), img.scaled(QSize(286,56),Qt::KeepAspectRatio, Qt::SmoothTransformation)); QTextCursor crs(&txt); crs.movePosition(QTextCursor::Start); // Tabellenformat verwenden, um das Bild rechtsbündig zu platzieren QTextTableFormat tableFormat; tableFormat.setAlignment(Qt::AlignRight); tableFormat.setBorder(0); tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100)); QTextCharFormat textformat; textformat.setFontPointSize(16); QTextTable *table = crs.insertTable(1, 2, tableFormat); crs = table->cellAt(0, 0).firstCursorPosition(); // Erste Zelle der ersten Zeile auswählen crs.insertText("Datenblatt xxx", textformat); crs = table->cellAt(0, 1).firstCursorPosition(); // Zweite Zelle der ersten Zeile auswählen QTextImageFormat imageFormat; imageFormat.setName("Logo.jpg"); crs.insertImage(imageFormat); pdfWriter.setPageSize(QPageSize(QPageSize::A4)); pdfWriter.setPageMargins(QMarginsF(10,10,10,10)); txt.setPageSize(QPageSize(QPageSize::A4).sizePoints()); txt.setDocumentMargin(0); txt.print(&pdfWriter); txt.print(&pdfWriter); } Mainwindow.ui consists of just a QPushButton named, surprise!, pushButton. There is also, for convenience, resource file (as you'd probably gather from cmake conf) having a placeholder logo and your html. res.qrc: <RCC> <qresource prefix="/"> <file>test.html</file> <file>Logo.png</file> </qresource> </RCC> Copy of your html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="generator" content="RocketCake"> <title></title> </head> <body style="background-color:#FFFFFF; padding:0; margin: 0;"> <div style="text-align:left;"> <table id="table_798fb160" cellpadding="3" cellspacing="1" style="box-sizing: border-box; vertical-align: bottom; position:relative; display: inline-table; width:50%; height:30px; background:none; Border: none; table-layout: fixed; "> <tr> <td width="100%" height="18px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_d0123cd"> <div style="text-align:left;"> <span style="font-size:12pt; font-family:Arial, Helvetica, sans-serif; color:#000000; "> </span> </div> </div> </td> </tr> </table> <table id="table_4bfff64d" cellpadding="3" cellspacing="1" style="box-sizing: border-box; vertical-align: bottom; position:relative; display: inline-table; width:100%; height:97px; background:none; border: 2px solid #000000; table-layout: fixed; "> <tr> <td width="27%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_6a5612c4"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">Projekt</span> </div> </div> </td> <td width="22%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_7a1f4a7c"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">{projekt}</span> </div> </div> </td> <td width="24%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_365f079f"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">Kundenposition</span> </div> </div> </td> <td width="25%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_798910f0"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">{kundenposition}</span> </div> </div> </td> </tr> <tr> <td width="27%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_6fab104c"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">Position / Revision</span> </div> </div> </td> <td width="22%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_3a151bc"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">{position} / {revision}</span> </div> </div> </td> <td width="24%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_63851a2"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">Aggregatnummer</span> </div> </div> </td> <td width="25%" height="15px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_30174d59"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">{aggregatnummer}</span> </div> </div> </td> </tr> <tr> <td width="27%" height="16px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_382cbccc"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">Datum</span> </div> </div> </td> <td width="22%" height="16px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_276db422"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">{datum}</span> </div> </div> </td> <td width="24%" height="16px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_49ec4bae"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">Artikelnummer</span> </div> </div> </td> <td width="25%" height="16px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_4c46cf44"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">{artikelnummer}</span> </div> </div> </td> </tr> <tr> <td width="27%" height="12px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_67c5a5c8"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; ">Bezeichnung</span> </div> </div> </td> <td width="22%" height="12px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_6530c995"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; "> </span> </div> </div> </td> <td width="24%" height="12px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_f645165"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; "> </span> </div> </div> </td> <td width="25%" height="12px" style="vertical-align: top; overflow:hidden; "> <div style="" id="cell_15ec8179"> <div style="text-align:left;"> <span style="font-size:8pt; font-family:Arial, Helvetica, sans-serif; color:#000000; "> </span> </div> </div> </td> </tr> </table>
  • how do I make the window title bar go dark

    Unsolved
    2
    0 Votes
    2 Posts
    161 Views
    posktomtenP
    Hello!@Blackzero The title bar belongs to the operating system. The operating system determines how the title bar should look.
  • Qt DBus XML howto

    Unsolved
    3
    0 Votes
    3 Posts
    619 Views
    M
    Hi! Maybe a little late, but I want to share it with future users on how to integrate DBus in Qt. When you need to send objects via DBus, your class must be described in XML so that Qt can generate the interface and adaptor for sending and receiving those objects. For example, with MyClass defined, you can run qdbuscpp2xml MyClass.h -o xmlMyClass.xml. If MyClass methods return or get standard parameters (supported types listed here: https://doc.qt.io/qt-6/qdbustypesystem.html), qdbuscpp2xml will generate everything for you. However, if the methods involve unsupported types, such as another custom object, you'll need to manually edit the XML file. Once your class is described in the XML file, use qdbusxml2cpp to generate the interface and adaptor, then connect them to the Bus. From there, you can use the interface to send and receive data. I haven't gone into full detail here to keep the comment concise, but I’ve written a blog post that covers this process more thoroughly, including how to edit the XML file for qdbusxml2cpp to generate a complete interface and adaptor. The post is based on Qt6, but it should also work with Qt5: https://scythe-studio.com/en/blog/how-to-use-d-bus-with-qt-6 I hope this helps!
  • Dynamic scaling UI components in Qt Creator

    Unsolved
    7
    0 Votes
    7 Posts
    707 Views
    S
    I am not sure if you need to support someone changing the system settings while your app is open. It is such an edge case that I would say it is okay for the user to close and reopen the app. However, this problem might occur when having two monitors with different scaling each. For this we react to showEvent, resizeEvent, and moveEvent to detect when the pixel ratio of the screen changes.
  • Qt windows

    Unsolved
    4
    0 Votes
    4 Posts
    198 Views
    Christian EhrlicherC
    Since 'dd' is a linux tool - try to find a similar tool for windows or install linux.
  • I have encountered some issues regarding the QT window DLL.

    Unsolved
    5
    0 Votes
    5 Posts
    261 Views
    J
    @SGaist Thank you. Let me ask.
  • signal and slot syntax when traversing a list of objects ?

    Solved
    14
    0 Votes
    14 Posts
    593 Views
    rsswdevR
    @Pl45m4 SettingsPage as an abstract class works fine now. Thanks all for the help
  • Login/Registration before accessing the application.

    Unsolved
    3
    0 Votes
    3 Posts
    184 Views
    artwawA
    @Kaustuv to add: if at all possible please ensure: all calls to API are using SSL; you compare hashes of the password instead of the real password. Something like SHA-512.
  • tableView->setModel(model); causes SIGSEGV.

    Solved
    27
    1 Votes
    27 Posts
    3k Views
    snubbenS
    Point taken! I will remove it. Thanks!
  • QTcpSocket ConnectToHost()

    Unsolved
    3
    0 Votes
    3 Posts
    201 Views
    V
    @JonB ok, thank you! I will check my program, maybe I do something wrong and there is the problem, not because I use incorrect port
  • Slow EC2 MySQL database (xampp) access

    Unsolved
    5
    0 Votes
    5 Posts
    262 Views
    JonBJ
    @DiogoIDENG There is nothing wrong with your query per se. A 1MB (is it really that small or did you mean 1GB?) is tiny. A nested query will run slower, but that is done up at the database server side, no WAN/latency etc. I'm surprised you even notice a speed difference, not sure what to make of that. On a WAN/where you have latency issuing a query for every letter typed is not a good idea. You could compensate for that by doing further work client-side instead. Think about your query: Where Designacao LIKE :designacao AND ID=:id_art I assume LIKE :designacao is used to pattern match against the characters being typed into the line edit. Let's say user starts by typing A as first character. The query returns all rows where Designacao starts with or has an A. Now the user types B as second character. You will issue a new query asking for those starting with or having AB. But by definition that will we a subset of those with A which you already have fetched to the client. So instead of the requerying the database you could just pick from those you already have without going back to the database. (Either do it yourself or use a QSortFilterProxyModel.) Miles faster. You have to deal with if user deletes the A or other such change which makes the original matching rows invalid, but that's not hard to do. Furthermore AND ID=:id_art looks like ID is the primary (or other unique?) key. In that case the query can only return either one or no records. Even less reason to go re-querying the database.
  • QTableView

    Unsolved
    2
    0 Votes
    2 Posts
    135 Views
    JonBJ
    @cc_cc said in QTableView: all the values ​​in the first column flash by When the mouse hovers over other rows, the value of the first column of that row will be displayed. Welcome. I for one do not understand what you are saying, especially about "flashing by", when it happens, what it looks like, etc.? This implies something is changing, once a QTableView is displaying data nothing should be changing. There should be no issue about displaying any columns from the table. Your code should only be a few lines long to test a minimal example.
  • Xlib.h include problem

    Unsolved
    8
    0 Votes
    8 Posts
    2k Views
    mrdebugM
    Have you never written and used a library? It is the same. Which is your doubt exactly?
  • Trying to build qt 5.15.14 x64 on windows.

    Unsolved
    14
    0 Votes
    14 Posts
    1k Views
    P
    James b-s have you succeeded building a 5.15.14 x64 windows msvc2022 build? I have tried the same, and while the build process completes, my build seems unable to run applications..
  • This topic is deleted!

    Unsolved
    3
    0 Votes
    3 Posts
    63 Views
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    4 Views
    No one has replied
  • reading multi-line input from QSocketNotifier

    Solved qsocketnotifier qtextstream
    4
    0 Votes
    4 Posts
    432 Views
    JonBJ
    @Joachim-W I looked at your progress here but have not had an opportunity to examine it further. But here are a couple of points which strike me: readLine() should read one line from input. It should not matter whether that comes from terminal (with or without pasting) or redirection. The fact that you seem to say sometimes it reads/returns one line and sometimes multiple lines should not happen. A line is a line. The QTextStream may (or may not) buffer further lines which are available (e.g. from redirection) but readLine() should only return a single line. When reading from redirection you can/should be able to read till "end of file", indicating the end of input. But when reading from terminal there is no "end", user could type more at any time, so no "end of file". You should not need a timer. One QSocketNotifier notification should be received when there is one or more lines/input available. Process all lines which are available (however you test for that) then exit. That should be it for the redirection case. For the terminal case at some future point a new QSocketNotifier notification should arrive at which point you re-enter and process whatever is available anew. You will need a readLine() call which returns with "empty" when no more input is currently available, or a test which says whether there is any further input available at this point before calling a blocking readLine(). It may be better to call readAll(): that should return all data which is available at that point, I believe, but will not block like readLine() when no further data is there. This will work for redirection too.