Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.7k Posts
  • Display layout distorted then the actual layout.

    Solved qt6.5 beginner help
    5
    0 Votes
    5 Posts
    738 Views
    A
    @Christian-Ehrlicher I understood now. Thank you!!
  • Ubuntu 22.04 how to reset QT_PLUGIN_PATH to correct value?

    Unsolved
    10
    0 Votes
    10 Posts
    4k Views
    JoeCFDJ
    @qt77 I guess you do not need it. Simply export QT_PLUGIN_PATH to the right location. Since you do not install qt development packages, the apps you use need qt libs which are installed by dependency. But the plugins path is not set automatically. I think it is good enough to set QT_PLUGIN_PATH(add it in bashrc). You can purge the installations. Be careful that you do not remove the libs your apps need. You can check which extra libs were installed. Simply purge these libs. But these libs do not hurt you if you leave them there. No worries. you can purge qtcreator and qmake for sure.
  • QWebEngineView exits with error

    Unsolved
    2
    0 Votes
    2 Posts
    151 Views
    SGaistS
    Hi, When and where are you doing that ? Is that view part of another widget ?
  • How to read syntax highlighting data from QTextDocument?

    Unsolved
    4
    0 Votes
    4 Posts
    271 Views
    SGaistS
    That does not answer my question. QSyntaxHighlighter is a class used to highlight text following some rules, it has no additional knowledge about what it highlights.
  • Does QT4.8 work on RHEL 8.8

    Unsolved
    4
    0 Votes
    4 Posts
    526 Views
    SGaistS
    @Axel-Spoerl good point ! I just have the habit of porting one major at a time depending on the classes used :-)
  • Need help can't find anything

    Unsolved
    3
    0 Votes
    3 Posts
    261 Views
    LahearleL
    update: I used the flickable method but find that it feels a little "jank" if I select all from the start of the https: it will act as normal, but when I click the righthand portion of the flickable, it auto sends the flickable back to the start (zero) which is not like a regular search bar. I set it to horizontal flick only and it's doable, but not ideal. sometimes when selecting I accidentally grab the flickable box and move the text, even though it's almost not there (child to a rectangle, so the text takes up most of the space). There has got to be a better way to do this, even if it involves using other modules?
  • GUI freezes caused by high stream rates

    Solved
    2
    0 Votes
    2 Posts
    234 Views
    jeremy_kJ
    @mtjsc00 said in GUI freezes caused by high stream rates: Hello, Firstly, sorry in advance for my poor english as it is not my first language. So, I have to create a powerful app that plots industrial robot positions in real-time. I wrote a demo app that runs a UDP server on a worker thread which fetches the data from the robot and emits a signal containing it. I use a QCustomPlot to plot the data. My problem is that generally the data stream rate we use is at 250 Hz but it can't be handled by the GUI which freezes if the user interacts. Surprisingly, my demo can go up to 100Hz before being saturated. Also I can't downsample the data fetched and I can't change the stream rate. Do you have an idea of how I can prevent GUI freezes at these stream rates ? (alternatives to QCustomPlot, Qt, software optimizations, ...). Thank you ! Hi, Your use of English is fine! First off, have you profiled to see where the time is spent? Optimizing outside of hotspots isn't going to yield much improvement. An extra thread emitting a signal per sample might make the situation worse, as each emission will result in a metacall event. Unless significant time is spent processing each datagram (verified through profiling), try performing all of the work in the GUI thread. If too much time is indeed spent per datagram, try to complete as much computation as possible before crossing a thread boundary. Is there a target frame rate for the application? While this may sound like the explicitly disallowed downsampling, computation on samples that will never be shown is wasted time. If the UI is expected to update at 30 or 60 Hz, try batching at that interval. Queue the updates, and use a timer to dispatch them at the desired rate. Prune samples that are superseded by later samples in the same update batch.
  • UDP reset

    Solved
    32
    0 Votes
    32 Posts
    4k Views
    V
    @Christian-Ehrlicher @JonB @jsulm Now,it is working.. #include <QCoreApplication> #include <QTextStream> #include <QtNetwork/QUdpSocket> #include <QObject> #include <QThread> #include <QtSerialPort> #include <QtSerialPort/qserialportinfo.h> #include <QSerialPortInfo> QUdpSocket *udpSocket; QTextStream output(stdout); qreal x ; qreal y ; qreal z ; QString x2,y2,z2; QByteArray datagram,datagram2; QHostAddress senderAddress2; quint16 senderPort2; QTimer *timer; bool state; static bool state2=true; void reset_again(); void send_reply() { datagram2.clear(); x = static_cast<qreal>(rand()) / RAND_MAX; y = static_cast<qreal>(rand()) / RAND_MAX; z = static_cast<qreal>(rand()) / RAND_MAX; x2 = QString::number(x); y2 = QString::number(y); z2 = QString::number(z); datagram2.append(x2); datagram2.append(","); datagram2.append(y2); datagram2.append(","); datagram2.append(z2); datagram2.append(","); int bytes=udpSocket->writeDatagram(datagram2, senderAddress2, senderPort2); if(bytes) { qDebug()<<"Data is successfully sent to" << senderAddress2.toString() << ":" << senderPort2 << "-" <<datagram2; } } void process_response() { if (udpSocket->state() == QUdpSocket::BoundState) { while (udpSocket->hasPendingDatagrams()) { datagram.resize(udpSocket->pendingDatagramSize()); QHostAddress senderAddress; quint16 senderPort; int bytesRead = udpSocket->readDatagram(datagram.data(), datagram.size(), &senderAddress, &senderPort); QString data = QString::fromUtf8(datagram); qDebug() << "Received datagram from" << senderAddress.toString() << ":" << senderPort << "-" << data; if (bytesRead == -1) { qDebug() << "Failed to read datagram!"; } senderAddress2 = senderAddress; senderPort2=senderPort; send_reply(); } } } void event_loop(); void reset_again() { qDebug()<<"No data is detected"; udpSocket->close(); event_loop(); } void event_loop() { output << "UDP Command Prompt is ready to receive data!" << "\n"; udpSocket = new QUdpSocket(); timer = new QTimer(); udpSocket->bind(QHostAddress::Any, 10050); state=QObject::connect(udpSocket, &QUdpSocket::readyRead,udpSocket, &process_response); while(state) { process_response(); if(udpSocket->waitForReadyRead(500)); else { state=false; reset_again(); } } } int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); event_loop(); return 0; }
  • 0 Votes
    9 Posts
    1k Views
    F
    @Christian-Ehrlicher Thank you for your advice. The sample code has been added to the bug report.
  • Convert QImage to QObject

    Unsolved
    3
    0 Votes
    3 Posts
    317 Views
    M
    @ChrisW67 thank you I couldn't put the following code together. This is my fault. void WpubEditor::on_Open_wpub_triggered() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open wpub file"), "", tr("wpub Files (*.wPub)")); if (!fileName.isEmpty()) { if (!m_pPubManager) { QString htmlPath = QFileInfo(__FILE__).dir().absolutePath() + "/canvas.html"; QFile file(htmlPath); if (file.exists()) { webView->load(QUrl::fromLocalFile(htmlPath)); } else { qDebug() << "Failed to load canvas.html. File not found."; } m_pPubManager = new WPubManager(this, nullptr); channel->registerObject("wpubManager", m_pPubManager); } if (m_pPubManager->OpenWPub(fileName)){ updateStatusBar(fileName); setMenuActionStatus(true); } else { qWarning("Couldn't open file."); } } }
  • How to get physicalDevice from QVulkan instance

    Unsolved
    1
    0 Votes
    1 Posts
    148 Views
    No one has replied
  • Customise Windows Taskbar entry

    Unsolved
    3
    0 Votes
    3 Posts
    484 Views
    B
    @JonB Thank you! I had never come across that terminology before, but that helped me to find this, which looks promising: https://doc.qt.io/qt-5/qml-qtwinextras-jumplist.html
  • error

    Unsolved
    3
    0 Votes
    3 Posts
    184 Views
    jsulmJ
    @Pappu-Kumar-Keshari I'm confused by the title of this thread: is there any error? Please use better titles.
  • QSql connection - maintaining keep alive

    Unsolved
    3
    0 Votes
    3 Posts
    264 Views
    Christian EhrlicherC
    For MySQL there are some options for this iirc.
  • A small suggestion for improving Qt

    Unsolved
    13
    0 Votes
    13 Posts
    1k Views
    N
    Hello, Chris Kawa and All! Thiago Macieira from Qt teams gave me the idea to use Qt metadata instead of a virtual function in class QObject! Now there is binary compatibility with Qt! https://github.com/Navadvipa-Chandra-das/PrabhupadaDictionaryQt The main change is that two virtual functions in the QObject base class have been removed! Now, the class that wants to be saved and restored using the Storage class must make two slots: public slots: void LoadFromStream( QDataStream &ST ); void SaveToStream( QDataStream &ST ); Meta-information is not inherited, and each class must still make these two slots, even if they will just call the ancestor method without adding any new code! But you can build an inheritance hierarchy and it works well. Probably the call is a little slower than calling a virtual function, but not the QObject class remains as fast as possible! That's what happened: O->LoadFromStream( *m_Stream ); And here's what happened now: InvokeSuccess = QMetaObject::invokeMethod( O, "LoadFromStream", Q_ARG( QDataStream&, *m_Stream ) ); Now let's see what the Qt team says! Interesting! Thank You! With best regards, Navadvipa Chandra dasa.
  • php extention used as lib in QT?

    Unsolved
    5
    0 Votes
    5 Posts
    569 Views
    Paul ColbyP
    Hi @shokarta, so thinking of using the dll from php connector and knowing how it works, to me it sounds much easier to use that Nope, that will not be easier. Definitely possible, but it will be a lot of work to implement, and maintain, so I'd consider that the last resort. To use that DLL, you would essentially have to embed the PHP runtime into your app. I've actually done this, in C++ (not Qt), commercially, very successfully (after a a lot of work), but that business had a large existing PHP codebase that needed to be shared (between existing apps, and a set of new high-speed AMQP message processors, using Apache Qpid... it was actually all very interesting, but I digress). But since you asked, I'll give you some code samples below to demonstrate the kinds of effort you'd need to do. And if you did, you'd end with a chain like: your-app -> php_embed -> php7-sapnwrfc -> official-NW-RFC-SDK -> NetWeaver As @SGaist suggested, you would much, much better off skipping the middle-components, and just doing: your-app -> official-NW-RFC-SDK -> NetWeaver Im having even harder time to setup SAP official SDK to use it in my QT project, Yeah, it can be tricky using third party SDKs in any language, but I'd focus your attention here. What trouble are you seeing trying to use the official SDK? If it's Qt specific, we're likely to be able to help, or if its general C/C++. Of course, if its a NW RFC SDK specific issue, then you should try SAP's support channels. Now that I've said "don't do the PHP approach"... here's a bit of what that would be involved (partly because this is knowledge I've never has reason to share ;) and partly to put you off it when you have likely better options to persue). php_embed PHP does provide an "php_embed" SAPI. See, for example, the libphp-embed package in Ubuntu. However, it is undocumented, and you need to figure things out by reading the source. I, for example, had to figure out the the init and de-init functions must be called from the same thread, or you'll get seemingly random crashes. Initialise Initialisation looks something like (of course this is using Boost, you'd want to refactor to use Qt or C++17+ equivalents): boost::unique_lock<boost::mutex> lock(initCountMutex); logTrace("begin initCount=" << initCount); // Initialise the global PHP module (if not already). if (initCount == 0) { logDebug("initialising PHP..."); if (initThreadId) { throw Exception("initCount is non-zero, but initThreadId is already valid", EXCEPTION_LOCATION); } php_embed_module.ub_write = php::global::ub_write; php_embed_module.log_message = php::global::log_message; php_embed_module.sapi_error = php::global::sapi_error; if (php_embed_init(argc, argv PTSRMLS_CC) != SUCCESS) { throw Exception("Failed to initialise global PHP module.", EXCEPTION_LOCATION); } initThreadId = boost::this_thread::get_id(); } // Increment the initialisation requests count. initCount++; logTrace("end initCount=" << initCount); And de-init: boost::unique_lock<boost::mutex> lock(initCountMutex); logTrace("begin initCount=" << initCount); // If this was the last instance, shutdown the PHP embed SAPI. if (initCount == 1) { logDebug("shutting down PHP..."); if (!initThreadId) { throw Exception("shutting down PHP, but initThreadId is not set", EXCEPTION_LOCATION); } else if (*initThreadId != boost::this_thread::get_id()) { throw Exception("final shutdown must be called from the " "same thread as the first initialise call", EXCEPTION_LOCATION); } php_embed_shutdown(TSRMLS_C); initThreadId.reset(); // This thread is no longer the initialisation thread. } else if (initCount < 1) { throw Exception("PHP shutdown requested when PHP not initialised", EXCEPTION_LOCATION); } // Decrement the initialisation requests count. initCount--; logTrace("end initCount=" << initCount); Execute PHP You'll need to marshall the C++/PHP types (will get to that in a minute), but the overall execution looks like: // Setup the PHP arguments. zval *param; TSRMLS_FETCH(); MAKE_STD_ZVAL(param); try { phpTypes::variantToZval(param, &in TSRMLS_CC); } catch (Exception &ex) { zval_dtor(param); FREE_ZVAL(param); ex.addLocation(EXCEPTION_LOCATION); throw ex; } zval *params[1] = { param }; // Call the PHP function. zval *functionNameZval, returnValue; MAKE_STD_ZVAL(functionNameZval); INIT_ZVAL(returnValue); int callStatus = FAILURE; std::string error; zend_first_try { ZVAL_STRING(functionNameZval, functionName.c_str(), 0); logDebug("Calling PHP function: " << Z_STRVAL_P(functionNameZval)); callStatus = call_user_function(EG(function_table), NULL, functionNameZval, &returnValue, 1, params TSRMLS_CC); } zend_catch { std::stringstream stream; stream << "PHP error with exit status " << EG(exit_status) << " while calling " << functionName; error = stream.str(); // It's not clear whether its safe to throw here, so we don't. } zend_end_try(); zval_dtor(param); // variantToZval will have copied the string's contents, so we free it here. FREE_ZVAL(param); //zval_dtor(functionNameZval); // functionNameZval has a reference to functionName.c_str(), so don't free it! FREE_ZVAL(functionNameZval); // If any errors occurred, throw an exception. if (!error.empty()) { if (callStatus != FAILURE) { // This should not happen, but just in case, log and error and prevent memory leaks. logNotice("a PHP error occurred, yet call_user_function returned SUCCESS"); zval_dtor(&returnValue); exit(0); } throw Exception(error, EXCEPTION_LOCATION); } // If call_user_function failed, also throw an exception. if (callStatus == FAILURE) { throw Exception("call_user_function returned FAILURE", EXCEPTION_LOCATION); } // Convert result to a variant. { zval * returnValuePointer = &returnValue; out = phpTypes::zvalToVariant(&returnValuePointer TSRMLS_CC); } zval_dtor(&returnValue); Now, hopefully you've already been put off the idea by this stage - there's an awful lot old-C API cruft going on here. Which is ok, if you have no other choice, but for a new app, I would 100% avoid. But just to round out the picture, the thing that's still missing is those phpTypes::variantToZval() and phpTypes::zvalToVariant() functions - those are some large functions which, in the case above, convert between qpid::type::variant (very similar to boost::variant) types and PHP's zval types. In your case, you'd want to marshall between QVariant and zval instead, and this is a lot of work too (and absolutely needs good unit tests!). Here's a very small taste for how that looks: #define ADD_TO_ARRAY(type, ...) { \ if (key == NULL) \ add_next_index_##type(output , ##__VA_ARGS__); \ else if (keyLength == (uint)-1) \ add_assoc_##type(output, key , ##__VA_ARGS__); \ else \ add_assoc_##type##_ex(output, key, keyLength , ##__VA_ARGS__); \ } #define SET_OR_ADD(TYPE, type, ...) \ if (add) { \ ADD_TO_ARRAY(type, ##__VA_ARGS__); \ } else { \ ZVAL_##TYPE(output , ##__VA_ARGS__); \ } void variantToZval( zval * const output, const qpid::types::Variant * const variant TSRMLS_DC, // Zend thread-safety arguments. const bool add, // Is output an array we should add to? const char *key, // If non-NULL, the associative array key. const uint keyLength // If non-default, the length of key. ) { switch (variant->getType()) { case qpid::types::VAR_VOID: SET_OR_ADD(NULL, null); break; case qpid::types::VAR_BOOL: SET_OR_ADD(BOOL, bool, variant->asBool()); break; case qpid::types::VAR_UINT8: case qpid::types::VAR_UINT16: case qpid::types::VAR_UINT32: case qpid::types::VAR_UINT64: { const uint64_t value = variant->asUint64(); if (value > LONG_MAX) { throw Exception("unsigned integer too large for PHP", EXCEPTION_LOCATION); } SET_OR_ADD(LONG, long, (long)value); } break; case qpid::types::VAR_INT8: case qpid::types::VAR_INT16: case qpid::types::VAR_INT32: case qpid::types::VAR_INT64: // this is not even half-way... So, in conclusion, I highly recommend you skip all the PHP stuff (even though it is technically possible, and actually kinda interesting), and focus your efforts on working with the official SAP NW RFC C/C++ SDK directly. You'll have less code, less bugs, less to maintain, and less dependencies if you go direct :) Cheers!
  • This topic is deleted!

    Unsolved
    3
    0 Votes
    3 Posts
    42 Views
  • QSertialPort and Bluetooth ...

    Unsolved
    2
    0 Votes
    2 Posts
    190 Views
    A
    @AnneRanch I am going to see if QBluetoothDevice class will fill the bill...
  • what is the preferred widget to display images?

    Unsolved
    2
    0 Votes
    2 Posts
    169 Views
    M
    @1XU7 Hi, QLabel ? https://doc.qt.io/qt-6/qtwidgets-widgets-imageviewer-example.html
  • Camera fails when i try to start it

    Unsolved
    1
    0 Votes
    1 Posts
    212 Views
    No one has replied