Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.7k Posts
  • QSvgRenderer and QByteArray problem

    Solved
    12
    0 Votes
    12 Posts
    1k Views
    JonBJ
    @JoeCFD I think I am just wrong to have said it does not scale. I think it does. Playing with it now....
  • QtCreator does not start from "Favorites" in Ubuntu 20.04 LTS

    Solved
    3
    0 Votes
    3 Posts
    225 Views
    kahlenbergK
    Ok, I solved my problem. OpenGL library was not installed. I looked at the journal with journalctl -f and saw the line: /usr/bin/qt/Tools/QtCreator/bin/qtcreator: error while loading shared libraries: libOpenGL.so.0: cannot open shared object file: No such file or directory Then I installed it with sudo apt install libopengl0 -y, it works now.
  • QCursor::setPos sets wrong X coordinates

    Unsolved
    7
    0 Votes
    7 Posts
    2k Views
    E
    Here a small program that shows the issue. I couldn't find a way to upload files so I copy pasted the content below. main.cpp: #include "myitem.hpp" #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QString> #include <QSurfaceFormat> #include <QUrl> #include <QtQml> int main(int argc, char** argv) { { QGuiApplication::setAttribute(Qt::ApplicationAttribute::AA_ShareOpenGLContexts); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setAttribute(Qt::AA_UseDesktopOpenGL); // Surface // Force OpenGL 3.3 core profile QSurfaceFormat format; format.setVersion(3, 3); format.setProfile(QSurfaceFormat::CoreProfile); QSurfaceFormat::setDefaultFormat(format); } QGuiApplication app(argc, argv); qmlRegisterType<MyItem>("MyLib", 1, 0, "MyItem"); QQmlApplicationEngine engine; engine.load(QUrl(QString("qrc:/qml/main.qml"))); return app.exec(); } myitem.hpp #pragma once #include <QQuickItem> #include <memory> class QMouseEvent; class MyItem : public QQuickItem { Q_OBJECT public: MyItem(QQuickItem* parent = nullptr); ~MyItem() override; protected: void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; private: void handleMouseWarping(QMouseEvent& event); private: struct Private; std::unique_ptr<Private> d; }; myitem.cpp #include "myitem.hpp" #include <QCursor> #include <QMouseEvent> #include <iostream> struct MyItem::Private { bool mouseWarpingEnabled{ false }; unsigned int mouseWarpingMargin{ 5u }; QCursor cursor; }; MyItem::MyItem(QQuickItem* parent) : QQuickItem{ parent }, d{ new Private } { setAcceptedMouseButtons(Qt::LeftButton); } MyItem::~MyItem() = default; void MyItem::mousePressEvent(QMouseEvent* event) { d->mouseWarpingEnabled = true; } void MyItem::mouseReleaseEvent(QMouseEvent* event) { d->mouseWarpingEnabled = false; } void MyItem::mouseMoveEvent(QMouseEvent* event) { handleMouseWarping(*event); } // ==== PRIVATE IMPL void MyItem::handleMouseWarping(QMouseEvent& event) { // Only manipulate QCursor coordinates to prevent having a desync between cursor and event information if(!d->mouseWarpingEnabled) { event.ignore(); return; } const auto globalPos = d->cursor.pos(); const auto topLeftRectPos = mapToGlobal({ 0, 0 }); const auto localPos = globalPos - topLeftRectPos; QPoint offset{ 0, 0 }; if(localPos.x() < d->mouseWarpingMargin) { offset.setX(width() - 2 * d->mouseWarpingMargin - 1); } else if(localPos.x() > width() - d->mouseWarpingMargin) { offset.setX(-(width() - 2 * d->mouseWarpingMargin - 1)); } if(localPos.y() < d->mouseWarpingMargin) { offset.setY(height() - 2 * d->mouseWarpingMargin - 1); } else if(localPos.y() > height() - d->mouseWarpingMargin) { offset.setY(-(height() - 2 * d->mouseWarpingMargin - 1)); } if(offset.x() != 0 || offset.y() != 0) { const auto newGlobalPos = globalPos + offset; d->cursor.setPos(newGlobalPos); const auto actualNewGlobalPos = d->cursor.pos(); std::cout << "Expected new coordinates: " << newGlobalPos.x() << ", " << newGlobalPos.y() << ". Actual new coordinates: " << actualNewGlobalPos.x() << ", " << actualNewGlobalPos.y() << std::endl; } } main.qml import QtQuick 2.15 import QtQuick.Controls 2.15 import MyLib 1.0 ApplicationWindow { id : root title : 'Mouse warping issue in 4K' visible : true width : 800 height : 400 color: Qt.hsla(0, 0, 0.13) MyItem { anchors.fill: parent Text { text: 'Press left-click down and move over to edge of window to warp to the other side' anchors.centerIn: parent color: Qt.hsla(0, 0, 0.89) } } } qml.qrc <RCC> <qresource prefix="/qml"> <file>main.qml</file> </qresource> </RCC>
  • call to non-static member function without an object argument

    Solved
    10
    0 Votes
    10 Posts
    9k Views
    jsulmJ
    @vatsk Please read and follow https://forum.qt.io/topic/113070/qt-code-of-conduct else you will be baned! I will delete your post as inappropriate and offensive.
  • problem with paths (or QPainter)

    Unsolved
    22
    0 Votes
    22 Posts
    3k Views
    M
    @J-Hilk said in problem with paths (or QPainter): the app bundle contains the binary version of it, not the human readable one If I look at Preview app, info.plist is a text file, but not writable. Maybe a extra process is needed to serialize the bundle ? right click on your project -> add new -> Files and Classes - Qt -> Qt Resource File than right click on the resource file -> add existing file/directory Yes I know, I was asking for an automatic process with a qmake command.
  • Is there possible to make and test qt program online ?

    Solved
    4
    1 Votes
    4 Posts
    2k Views
    Q
    @SGaist said in Is there possible to make and test qt program online ?: JupyterHub no just like online GDB for c
  • mac os sdk12 not working with Qt bluetooth

    Unsolved
    4
    0 Votes
    4 Posts
    906 Views
    A
    Yes I noticed already that there are bug reports for qt 6.2 and macOS 12. As you said the scanning is working outside if you the add the key in the Info.plist. This works for starting the scanning but it does not find any Low Energy Devices. Or could you scan for Low energy devices at all?
  • From the Qt blog: Widgets on a header

    4
    0 Votes
    4 Posts
    1k Views
    M
    https://www.qt.io/blog/2012/09/28/qt-support-weekly-27-widgets-on-a-header
  • finding similar functions of QTableWidget as that of QTableView

    Solved
    5
    0 Votes
    5 Posts
    623 Views
    Swati777999S
    @JonB With some experimentation, I got the desired result.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    18 Views
    No one has replied
  • How to react to light/dark mode changes in macos?

    Unsolved
    5
    0 Votes
    5 Posts
    2k Views
    J.HilkJ
    a swift (hehe) google search resulted in this so topic https://stackoverflow.com/a/52406553/15422846 its objective c, so you should be able to include it in your c++ project
  • Array of widgets and inputting the limit of for-loop iteration from the users

    Solved
    8
    0 Votes
    8 Posts
    1k Views
    Swati777999S
    @Thank-You I've shared my solution and marked it as the best answer. Thanks.. :)
  • 0 Votes
    13 Posts
    1k Views
    S
    @SocketSackett Continuing ... I found the suggestion on Stack Overflow to use: db = QSqlDatabase(); db.removeDatabase(cnxn); after the close was a way to fix the duplicate connection close error. This is wrong. Doing this will not allow the work done to be updated. I removed that, & did a straight DB close, & it is updating once again. Checking for pre-existence of DB path with the QSqlDatabase::database.isValid() will suffice & is a good approach.
  • 0 Votes
    16 Posts
    2k Views
    pgiovanniP
    AH I FIGURED IT OUT. So for whatever reason, since i was creating a new QGroupBox pieGroup every time the function was called that somehow prevented the title from updating. So I changed it to create the new groupbox on the first click only. Now all the other clicks just update the title. I don't know what's going on under the covers. but it works now.
  • General question about qmake

    Solved
    4
    0 Votes
    4 Posts
    451 Views
    D
    @raven-worx Not at all sure what I did wrong before (it's been a while), but did just what I would have expected it to do. Problem solved
  • How to exclude generated moc_files from direct compilation?

    Unsolved
    2
    0 Votes
    2 Posts
    200 Views
    SGaistS
    Hi, If you declare slots, you need to have them implemented even if the method is empty.
  • 0 Votes
    3 Posts
    1k Views
    raven-worxR
    @Dariusz said in cmake automoc + dll... error LNK2001: unresolved external symbol "public: static struct QMetaObject: Do I have to write some kind of post build command that copies all moc files to some location & ship it with my dll/include folder? no, the moc data is compiled into your binary, like any other class/method etc. Since you are using cmake, did you set the AUTOMOC property?! https://doc.qt.io/qt-6/cmake-get-started.html
  • Qt and pkg-config

    Unsolved
    12
    0 Votes
    12 Posts
    2k Views
    SGaistS
    Qt has support for pkg-config both to use it to link to libraries as well as for the lib template. From the looks of it, on Debian, there are .pc files available for the various Qt modules.
  • Experimenting with the layouts

    Unsolved
    3
    0 Votes
    3 Posts
    276 Views
    JoeCFDJ
    Try it in designer which has preview ==>Form==>Preview in==>Fusion Style to make sure the layouts are right and then generate your C++ code.
  • QScreen returning the wrong size for my monitor

    Unsolved
    6
    0 Votes
    6 Posts
    3k Views
    M
    @feistykittykat Thank you very much! That worked for me as well. Was driving me nuts that it used to work when I was doing 5.x development and since going to 6.2.1 I have found a lot of gotchas in my code!