Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k Topics 456.5k Posts
  • How to build qt charts with profile option in mingw64?

    Unsolved
    1
    0 Votes
    1 Posts
    136 Views
    No one has replied
  • QOpenGLWidget cpu usage is abnormal

    Unsolved
    1
    0 Votes
    1 Posts
    135 Views
    No one has replied
  • Problem on changing QSqlRetionalTableModel result column value.

    Unsolved
    2
    0 Votes
    2 Posts
    148 Views
    SGaistS
    Hi, You are using the wrong tool. You should not try to change the data, it's only a viewing thing. You should rather implement a custom QStyledItemDelegate and implement the displayText method. In there do your transformation.
  • Open file with double click on Mac

    Locked Unsolved
    11
    0 Votes
    11 Posts
    5k Views
    SGaistS
    @ghart976 hi and welcome to devnet, You should either give more details or better: open a new thread about the topic you want to discuss. This one is 7 years old and not related to zsh at all but Finder.
  • QMetaType casting to desired type

    Unsolved
    11
    0 Votes
    11 Posts
    2k Views
    jeremy_kJ
    @Redman said in QMetaType casting to desired type: @jeremy_k I'm talking QtRemoteObjects. I intentionally left that piece of information out because every time I mention them in this forum my posts never get answered. That's an important detail. It sounds like a useful project. I personally have remained minimally interested due to the project's stated lack of interest in compatibility with non-QRO implementations. I'm not lucky enough to work in a distributed environment where all nodes run a compatible Qt application. This switch statement is gonna get bigger and bigger aswell as be error prone. Is there any way to make this piece of code dynamic? I was imagining: template <class Type, class... Others> std::any convert(void *obj) { QMetaType fromType = QMetaType::fromType<NetworkClass>(); QMetaType toType = QMetaType::fromType<Type>(); std::any ret; if QMetaType::canConvert(fromType, toType) { QMetaType::convert(obj, fromType, &ret, toType); return ret; } else return convert<Others...>(obj); } template <> convert(void *obj) { return std::any(nullptr); } NetworkClass *obj = getObject(); std::any convertedObject = convert<Type1, Type2, Type3>(obj); if (std::any_cast<void *>(convertedObject) != nullptr) ... Not expected to compile as is Not runtime dynamic The user of the std::any will need to know what it wants to convert it to I'm not sure this improves the situation.
  • Json iteration

    Unsolved
    3
    0 Votes
    3 Posts
    271 Views
    R
    @JonB Thanks for the hints
  • adding new class in Qt Creator

    Unsolved
    8
    0 Votes
    8 Posts
    494 Views
    H
    @jsulm @Sebastiano-Zamberlan ok, thank you, I found it... strange, that there's no hint in the helpfiles how to do such a simple thing.....
  • Integrate Q3DScatter into Mainwindow ui using QWidget as window container

    Unsolved
    2
    0 Votes
    2 Posts
    200 Views
    jsulmJ
    @Antoi said in Integrate Q3DScatter into Mainwindow ui using QWidget as window container: I'm trying to create a QWidget as a window container Why? Q3DScatter is a QWidget...
  • my application installed on drive D report error "cant not find Qt6WebEngineCore.dll"

    Unsolved
    1
    0 Votes
    1 Posts
    285 Views
    No one has replied
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • Question about connect() function with the SIGNAL and SLOT macros

    Solved
    5
    0 Votes
    5 Posts
    614 Views
    Pl45m4P
    @szmf To add: One more situation where you could face different behavior is when you are dealing with parent inside a QObject. Let's say your QObject has a fixed parent, which never changes (important) during its lifetime. Assume a signal foo() that is connected to a slot called bar() in your parent class. This works (besides it's not recommended or a good practise to do so): connect(this, SIGNAL(foo()), parent(), SLOT(bar()); while none of these work, for the same reason mentioned above: connect(this, &MyClass::foo, parent(), &ParentClass::bar); connect(this, &MyClass::foo, parent(), &QObject::bar); connect(this, &MyClass::foo, parentWidget(), &QWidget::bar); During compilation parent is not definite, therefore you would get an error that slot bar() can't be resolved / was not found. Whereas the first example works, as the check is performed at runtime where parent() is already linked to your actual parent class, which should hold a slot called bar().
  • qttexttospeech

    Unsolved
    3
    0 Votes
    3 Posts
    198 Views
    Ronel_qtmasterR
    @mondayboy [image: 64cca7d9-5d33-430a-8728-ae7179a24d13.PNG] in the demo here i have English and German
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • QComboBox width would changed when it setstylesheet

    Solved
    6
    0 Votes
    6 Posts
    843 Views
    HansonH
    @Abderrahmene_Rayene Oh!!!!It works!!!Thank you so much!!!
  • Qt Designer custom widget plugin confusion

    Unsolved
    2
    0 Votes
    2 Posts
    264 Views
    Christian EhrlicherC
    A plugin built with an older Qt version than the app wich is using this plugin is fine. It can not be newer for obvious reasons as the plugin might use a new api call.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • QPermission usage question

    Unsolved
    2
    0 Votes
    2 Posts
    268 Views
    C
    @RogueWarrior Not every platform a Qt application can be deployed on is Apple or Android. Even if your metadata indicates that your application wants GPS access I expect the user can deny it. So, on Mac for example, you appear to still need to check in code that permission is there. This is what I expect QPermission wraps in a platform-agnostic fashion.
  • QTcpServer won't receive client data on connected QTcpSocket

    Solved
    24
    0 Votes
    24 Posts
    3k Views
    D
    @dmitttri [SOLVED] I am posting the solution for the original post: Client had an issue, after socket write call it's required to call sync waitForBytesWritten, which will process actual socket writing Server had an issue, in the run method, we can't just call socket read, it's required to call waitForReadyRead which takes care to process socket and fill it with incoming data. Thanks everyone for their suggestions and help! I am also posting working sample code, which is only meant for demo purposes, to show a simple synchronous approach to TCP client and server DEMO TCP CLIENT AND SERVER WITH THREADS MainClient.cpp #include "SimpleClient.h" int main(int argc, char *argv[]) { SimpleClient client; if (!client.connectToServer("127.0.0.1", 9000)) { return -1; } if (!client.pokeServer("Hello Server")) { return -1; } return 0; } SImpleClient.h #ifndef SIMPLECLIENT_H #define SIMPLECLIENT_H #include <QTcpSocket> #include <QAbstractSocket> #define SOCKET_OPERATION_TIMEOUT_MS 3000 class SimpleClient { public: SimpleClient(); bool connectToServer(QString serverIP, qint16 serverPort); int pokeServer(const char *pokeMsg); private: QTcpSocket *socket = nullptr; }; #endif // SIMPLECLIENT_H SImpleClient.cpp #include <QByteArray> #include "SimpleClient.h" SimpleClient::SimpleClient() { this->socket = new QTcpSocket; } bool SimpleClient::connectToServer(QString serverIP, qint16 serverPort) { qDebug() << "Connecting to" << serverIP << ":" << serverPort; socket->connectToHost(QHostAddress(serverIP), serverPort); if (!socket->waitForConnected(SOCKET_OPERATION_TIMEOUT_MS)) { qDebug() << socket->errorString(); return false; } qDebug() << "Connected"; return true; } int SimpleClient::pokeServer (const char *pokeMsg) { qDebug() << "Sending :" << QString(pokeMsg); this->socket->write(pokeMsg, strlen(pokeMsg)); if (!this->socket->waitForBytesWritten(SOCKET_OPERATION_TIMEOUT_MS)) { qDebug() << socket->errorString(); return false; } if (!this->socket->waitForReadyRead(SOCKET_OPERATION_TIMEOUT_MS)) { qDebug() << this->socket->errorString(); return false; } QByteArray serverReply = this->socket->readAll(); QString replyString(serverReply.data()); qDebug() << "Received:" << replyString; qDebug() << "Success"; return true; } MainServer.cpp #include <QCoreApplication> #include <QtCore> #include "SimpleServer.h" int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); SimpleServer server; server.start("127.0.0.1", 9000); return app.exec(); } SimpleServer.h #ifndef SIMPLESERVER_H #define SIMPLESERVER_H #include <QDebug> #include <QTcpServer> class SimpleServer : public QTcpServer { Q_OBJECT; public: SimpleServer(QObject *parent = nullptr); bool start(QString serverIP, qint16 serverPort); protected: void incomingConnection(qintptr socketDescriptor) override; \ }; #endif // SIMPLESERVER_H SimpleServer.cpp #include <QHostAddress> #include "SimpleServer.h" #include "ServerJobThread.h" SimpleServer::SimpleServer(QObject *parent) : QTcpServer(parent) {} bool SimpleServer::start(QString serverIP, qint16 serverPort) { qDebug() << "Awaiting for new connections " << "IP" << serverIP << "PORT" << serverPort; this->listen(QHostAddress(serverIP), serverPort); return true; } void SimpleServer::incomingConnection(qintptr socketDescriptor) { qDebug() << "New incoming connection"; ServerJobThread *thread = new ServerJobThread(socketDescriptor, this); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); } ServerJobThread.h #ifndef SERVERJOBTHREAD_H #define SERVERJOBTHREAD_H #include <QThread> #include <QTcpSocket> class ServerJobThread : public QThread { Q_OBJECT public: ServerJobThread(qintptr socketDescriptor, QObject *parent); void run() override; private: qintptr socketDescriptor; }; #endif // SERVERJOBTHREAD_H ServerJobThread.cpp #include <QByteArray> #include <QTime> #include "ServerJobThread.h" #define SOCKET_OPERATION_TIMEOUT_MS 3000 #define THREAD_MAX_RUNNING_TIME_S 5 #define THREAD_ID this->currentThreadId() ServerJobThread::ServerJobThread(qintptr socketDescriptor, QObject *parent) : QThread(parent) { this->socketDescriptor = socketDescriptor; } void ServerJobThread::run() { bool workerThreadShouldRun = true; QTcpSocket tcpSocket; if (!tcpSocket.setSocketDescriptor(this->socketDescriptor)) { qDebug() << THREAD_ID << "setSocketDescriptor fail"; return; } QTime workerThreadTimeoutTime = QTime::currentTime().addSecs(THREAD_MAX_RUNNING_TIME_S); while (workerThreadShouldRun) { if (tcpSocket.bytesAvailable() == 0) { tcpSocket.waitForReadyRead(SOCKET_OPERATION_TIMEOUT_MS); } else { QByteArray buffer = tcpSocket.readAll(); if (buffer.size() > 0) { qDebug() << THREAD_ID << "Received:" << QString(buffer.data()); qDebug() << THREAD_ID << "Sending :" << QString("Hello Client"); tcpSocket.write("Hello Client"); tcpSocket.waitForBytesWritten(SOCKET_OPERATION_TIMEOUT_MS); workerThreadShouldRun = false; } if (QTime::currentTime() > workerThreadTimeoutTime) { qDebug() << THREAD_ID << "Thread max running time expired"; workerThreadShouldRun = false; } } } qDebug() << THREAD_ID << "Thread finished"; } CMakeLists.txt cmake_minimum_required(VERSION 3.14) project(Simple-TCP-Client-Server 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 Core Network) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS core Network) add_executable(Server ServerJobThread.h ServerJobThread.cpp SimpleServer.h SimpleServer.cpp MainServer.cpp ) target_link_libraries(Server Qt6::Core Qt6::Network) add_executable(Client SimpleClient.h SimpleClient.cpp MainClient.cpp ) target_link_libraries(Client Qt6::Core Qt6::Network) CLIENT STDOUT $ ./Client Connecting to "127.0.0.1" : 9000 Connected Sending : "Hello Server" Received: "Hello Client" Success SERVER STDOUT $ ./Server Awaiting for new connections IP "127.0.0.1" PORT 9000 New incoming connection 0x9a60 Received: "Hello Server" 0x9a60 Sending : "Hello Client" 0x9a60 Thread finished
  • Project ERROR: This module does not accept configure command line arguments.

    Unsolved
    2
    0 Votes
    2 Posts
    198 Views
    SGaistS
    Hi and welcome to devnet, From the looks of it, I think it's thé -I and -L arguments that are wrong. If memory serves well, there's a space unlike when you pass them to the compiler. That said, why use OpenSSL ? macOS provides their implemention of secure transport.
  • Back to "sender()" analysis...

    Unsolved
    4
    0 Votes
    4 Posts
    405 Views
    Axel SpoerlA
    @AnneRanch said in Back to "sender()" analysis...: How can I fix this: sender()always returns a QObject *. If you want to access members of a class inheriting from QObject, e.g. MainWindow_Bluetooth, qobject_cast is your friend. It's documentation is here.