Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k Topics 456.4k Posts
  • how do I find a primary key using a QSqlRelationalTableModel?

    Unsolved sql model
    4
    0 Votes
    4 Posts
    553 Views
    JonBJ
    @jdent You have to iterate through the rows looking for the value you want. If you use a QSortFilterProxyModel you can take advantage of binary search for speed if you sort by primary key. QSqlRelationalTableModel is not important here, all that gives is a "lookup" on one field to map e.g. an integer value to a corresponding string from a related table for display.
  • Couldn't build drivers for mysql QT 6.7.0

    Unsolved
    5
    0 Votes
    5 Posts
    480 Views
    D
    @Christian-Ehrlicher Thanks for the assistance. I managed to build and install it. Found the dylib and manually pasted it into ../macos/plugins/sqldrivers and in the build directory of my program but my program says that it still can not find the driver. I will provide some screenshots. If you notice anything wrong please let me know. Sorry for the link but they are too large apparently https://imgur.com/a/qPy7eko
  • Flipping QGraphicsRectItem on mouse move?

    Unsolved qt c++ qgraphicsitem
    3
    0 Votes
    3 Posts
    519 Views
    S
    I tried to debug further but some things i get are just strange. I can't figure out why this happens: ORIG TOP LEFT 0 ORIG BOTTOM RIGHT QPointF(450,292) ORIG TOP LEFT 0 ORIG BOTTOM RIGHT QPointF(450,292) ORIG TOP LEFT 0 ORIG BOTTOM RIGHT QPointF(450,250) ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250) ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250) ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250) ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250) ORIG TOP LEFT nan ORIG BOTTOM RIGHT QPointF(450,250) Here is the code i get the debbug from: #include "handleitem.h" #include "resizablehandlerect.h" #include <QGraphicsSceneMouseEvent> #include <QDebug> #include "resizablepixmapitem.h" HandleItem::HandleItem(Position position) : handlePosition(position) { setFlag(QGraphicsItem::ItemIsMovable); } void HandleItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { ResizableHandleRect *rectItem = dynamic_cast<ResizableHandleRect *>(parentItem()); if (!rectItem) { return; // Wenn das Parent-Item kein ResizableHandleRect ist, beende die Funktion } QRectF boundingFrameRect = rectItem->selectorFrameBounds(); OriginTopLeft = mapToScene(boundingFrameRect.topLeft()); OriginBottomRight = mapToScene(boundingFrameRect.bottomRight()); QRectF SceneBoundingFrameRect(OriginTopLeft, OriginBottomRight); qDebug() << "ORIG TOP LEFT" << OriginLeftCenter << "ORIG BOTTOM RIGHT" << OriginBottomRight; OriginBottomCenter = SceneBoundingFrameRect.bottom(); OriginTopCenter = SceneBoundingFrameRect.top(); BottomCenterWasDragged = false; TopCenterWasDragged = false; } void HandleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { ResizableHandleRect *rectItem = dynamic_cast<ResizableHandleRect *>(parentItem()); if (!rectItem) { return; // Wenn das Parent-Item kein ResizableHandleRect ist, beende die Funktion } QRectF boundingFrameRect = rectItem->selectorFrameBounds(); QPointF topLeft = mapToScene(boundingFrameRect.topLeft()); QPointF bottomRight = mapToScene(boundingFrameRect.bottomRight()); QRectF SceneBoundingFrameRect(topLeft, bottomRight); //qDebug() << "HandlePosition: " << handlePosition; switch (handlePosition) { case TopLeft: break; case TopCenter: SceneBoundingFrameRect.setTop(event->scenePos().y()); if(SceneBoundingFrameRect.bottom() < SceneBoundingFrameRect.top() && BottomCenterWasDragged == false){ qDebug() << "-- (2)SWITCH Top to Bottom"; handlePosition = BottomCenter; TopCenterWasDragged = true; } break; case TopRight: break; case RightCenter: break; case BottomRight: break; case BottomCenter: SceneBoundingFrameRect.setBottom(event->scenePos().y()); if(SceneBoundingFrameRect.bottom() < SceneBoundingFrameRect.top() && TopCenterWasDragged == false){ qDebug() << "(1)SWITCH Bottom to Top--"; handlePosition = TopCenter; BottomCenterWasDragged = true; } break; case BottomLeft: break; case LeftCenter: break; default: break; } if(SceneBoundingFrameRect.topLeft() != OriginTopLeft && BottomCenterWasDragged == true){ SceneBoundingFrameRect.setTopLeft(OriginTopLeft); BottomCenterWasDragged = false; qDebug() << "(1*)Correct Top, Bottom was Dragged!" << SceneBoundingFrameRect.topLeft(); } if(SceneBoundingFrameRect.bottomRight() != OriginBottomRight && TopCenterWasDragged == true){ SceneBoundingFrameRect.setBottomRight(OriginBottomRight); TopCenterWasDragged = false; qDebug() << "(2*)Correct Bottom, Top was Dragged!" << SceneBoundingFrameRect.bottomRight(); } QPointF topLeft2 = mapFromScene(SceneBoundingFrameRect.topLeft()); QPointF bottomRight2 = mapFromScene(SceneBoundingFrameRect.bottomRight()); QRectF NEWBoundingFrameRect2(topLeft2, bottomRight2); rectItem->setSelectorFrameBounds(NEWBoundingFrameRect2);
  • 0 Votes
    2 Posts
    360 Views
    Christian EhrlicherC
    If you want only a single instance of your application running you should take a look at QtSingleApplication
  • Style mistake in win11 with Qt 6.7+ mingw 11.2 official online release.

    Solved
    8
    0 Votes
    8 Posts
    1k Views
    Axel SpoerlA
    That’s a known bug. Working on it…..
  • Advice on Twitter like interface

    Unsolved
    7
    0 Votes
    7 Posts
    610 Views
    P
    @SGaist Roger that 🫡 One of the things that I want to use heavily are emojis, glad that Qt seems to render all of them just fine in QString https://emojipedia.org/saluting-face https://stackoverflow.com/questions/41617473/qt-application-shows-emoji-instead-of-unicode-character
  • declare pointers to controls in .ui file

    Unsolved
    6
    0 Votes
    6 Posts
    308 Views
    SGaistS
    @Bryan-Kelly Designer does not care about headers, it's a visual tool. You want to use a class, you need to include its header where you use it. Check the includes at the top of your cpp file.
  • About commercial use

    Solved
    2
    0 Votes
    2 Posts
    192 Views
    SGaistS
    Hi, No there's not such thing. You can audit the code if in doubt. The Qt Telemetry module is for the developer to implement telemetry for their app.
  • How to add second status bar and display it above the first one?

    Unsolved
    4
    0 Votes
    4 Posts
    683 Views
    Axel SpoerlA
    @Christian-Ehrlicher Shame on me.
  • Cancel QTimer singleShot

    Solved qtimer timer cancel
    3
    0 Votes
    3 Posts
    553 Views
    J
    @JonB thank you
  • QTimer::singleShot()'s syntax

    Solved
    34
    1 Votes
    34 Posts
    12k Views
    J
    @JKSH thank you :)
  • RTS/CTS in QSerialPort

    Unsolved
    6
    0 Votes
    6 Posts
    678 Views
    A
    OK, " we " have a RTS/CTS defined . That in my opinion is not the issue. As bad as "terminal" is not documented , it is also not the issue here. The code posted demonstrate the sequence of outputting / showing/ displaying the ASCII character in "console" . Since this GROUP ( "we ") is actuality using "terminal" , can "'we" make a group effort to find HOW / where is "terminal" code implementing RTS/CTS ? I do not see it in "console". The last line of code just stops output when "RTS/CTS" flow is implemented. Eventually, after all this is resolved , I like to be able to "emulate CTS " thus bypassing the hardware - for test purpose, Actually I like to see the code - in "console" referencing "Settings p = m_settings->settings();"
  • Bluetooth peripheral receive from a write characteristic

    Solved
    2
    0 Votes
    2 Posts
    309 Views
    G
    Ignore that, I should've gone back and re-read the documentation... characteristicChanged() is the QLowEnergyService signal that you want for this.
  • i cant install Qt

    Locked Unsolved
    2
    0 Votes
    2 Posts
    157 Views
    Christian EhrlicherC
    @QtLover02 Why a double post? https://forum.qt.io/topic/155995
  • QPrime error in qtgrace

    Unsolved
    2
    0 Votes
    2 Posts
    160 Views
    Christian EhrlicherC
    @bhabanist said in QPrime error in qtgrace: Any suggestions? Ask the developer of the software what is going wrong. I don't see what we can do here.
  • i cant install Qt

    Unsolved
    2
    0 Votes
    2 Posts
    219 Views
    Axel SpoerlA
    @QtLover02 Which platform are you trying to install on? It looks like the platform doesn't have a screen. In this case, you have to use command line options only. See here.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • IS QTSocket a bogus?

    Unsolved
    14
    0 Votes
    14 Posts
    957 Views
    C
    @mariappan Perhaps if you run this client/server pair you will better understand what is happening, and why this is not "a bogus". Client: #ifndef CLIENT_H #define CLIENT_H #include <QObject> #include <QTcpSocket> #include <QTimer> class Client : public QObject { Q_OBJECT public: explicit Client(QObject *parent = nullptr); private slots: void handleConnected(); void handleDisconnected(); void handleErrorOccurred(QAbstractSocket::SocketError socketError); void handleBytesWritten(qint64 bytes); void sendPacket(); private: QTcpSocket *m_socket; QTimer *m_timer; int m_packetNo; }; #endif // CLIENT_H #include "client.h" #include <QTimer> #include <QRandomGenerator> Client::Client(QObject *parent) : QObject{parent} , m_socket{ new QTcpSocket(this) } , m_timer{ new QTimer(this) } , m_packetNo{0} { m_timer->setInterval(500); connect(m_timer, &QTimer::timeout, this, &Client::sendPacket); connect(m_socket, &QTcpSocket::connected, this, &Client::handleConnected); connect(m_socket, &QTcpSocket::disconnected, this, &Client::handleDisconnected); connect(m_socket, &QTcpSocket::errorOccurred, this, &Client::handleErrorOccurred); connect(m_socket, &QIODevice::bytesWritten, this, &Client::handleBytesWritten); m_socket->connectToHost(QHostAddress("127.0.0.1"), 12345); } void Client::handleConnected() { qDebug() << "Connected, sending packets."; m_timer->start(); } void Client::handleDisconnected() { qDebug() << "Disconnected"; m_timer->stop(); } void Client::handleErrorOccurred(QAbstractSocket::SocketError socketError) { qDebug() << "Error occured" << socketError; m_timer->stop(); } void Client::handleBytesWritten(qint64 bytes) { qDebug() << "Bytes written" << bytes; } void Client::sendPacket() { // Generate a sample fixed-length payload QByteArray data; data.setNum(m_packetNo++); data = data.rightJustified(32, '.'); m_socket->write(data); qDebug() << "Wrote" << data; // Sometimes we write more than one quint32 value = QRandomGenerator::global()->generate(); if ((value % 3) == 1) { data.setNum(m_packetNo++); data = data.rightJustified(32, '*'); m_socket->write(data); qDebug() << "Wrote" << data; } } #include <QCoreApplication> #include <QDebug> #include <QTimer> #include "client.h" int main(int argc, char **argv) { QCoreApplication app(argc, argv); Client client; QTimer::singleShot(30000, qApp, &QCoreApplication::quit); return app.exec(); } Server: #ifndef SERVER_H #define SERVER_H #include <QObject> #include <QTcpServer> class Server : public QObject { Q_OBJECT public: explicit Server(QObject *parent = nullptr); private slots: void handleNewConnection(); private: QTcpServer *m_server; }; class ClientHandler: public QObject { Q_OBJECT public: explicit ClientHandler(QTcpSocket *socket, QObject *p = nullptr); private slots: void handleReadyRead(); void handleDisconnected(); private: QTcpSocket *m_socket; }; #endif // SERVER_H #include "server.h" #include <QDebug> #include <QTcpSocket> Server::Server(QObject *parent) : QObject{parent} , m_server{ new QTcpServer(this) } { connect(m_server, &QTcpServer::newConnection, this, &Server::handleNewConnection); m_server->listen(QHostAddress("127.0.0.1"), 12345); } void Server::handleNewConnection() { while(m_server->hasPendingConnections()) { QTcpSocket *socket = m_server->nextPendingConnection(); qDebug() << "Accepted connection from " << socket->peerAddress() << socket; ClientHandler *client = new ClientHandler(socket, this); Q_UNUSED(client); } } ClientHandler::ClientHandler(QTcpSocket *socket, QObject *p) : QObject(p) , m_socket(socket) { socket->setParent(this); connect(socket, &QTcpSocket::readyRead, this, &ClientHandler::handleReadyRead); connect(socket, &QTcpSocket::disconnected, this, &ClientHandler::handleDisconnected); } void ClientHandler::handleReadyRead() { qDebug() << m_socket<< "readyRead received."; QByteArray data = m_socket->readAll(); qDebug() << data; } void ClientHandler::handleDisconnected() { qDebug() << m_socket << "disconnect"; deleteLater(); } #include <QCoreApplication> #include "server.h" int main(int argc, char **argv) { QCoreApplication app(argc, argv); Server server; return app.exec(); }
  • Convert QLineEdit to float

    Unsolved
    13
    0 Votes
    13 Posts
    1k Views
    Pl45m4P
    @Bryan-Kelly I can only recommend you to read these first: Basic project setup: https://doc.qt.io/qt-6/designer-using-a-ui-file.html https://doc.qt.io/qtcreator/creator-writing-program.html Qt specific things you should know: https://doc.qt.io/qt-6/metaobjects.html https://doc.qt.io/qt-6/objecttrees.html https://doc.qt.io/qt-6/signalsandslots.html https://doc.qt.io/qt-6/eventsandfilters.html Knowing this (not perfectly) in combination with a solid C++ skill level is a good start.
  • Error: Unable to create the C++ code.

    Unsolved
    2
    0 Votes
    2 Posts
    310 Views
    JonBJ
    @jiapei100 If you do not get an answer here sign up to the PyQt mailing list, https://www.riverbankcomputing.com/mailman/listinfo/pyqt, and ask there.