Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.3k Posts
  • QLineEdit and pasted text

    Solved
    9
    0 Votes
    9 Posts
    959 Views
    R
    @Pl45m4 Thank you for the useful suggestions. I think I shall connect a slot to the QClipboard::dataChanged() signal in order to show a button which the user can press to paste the new text into the control. Of course, if the user pastes directly into the control with Ctrl-V, for example, or a context menu, then the text will not be filtered. Also not if typing, which is why I do not want to use QValidator. It is only for convenience, so using a separate button to insert the clipboard text gives me greater flexibility.
  • run cmd in qt

    Solved
    2
    0 Votes
    2 Posts
    198 Views
    C
    "It doesn't work" is not a good problem description. However, a self-contained program demonstrating the problem is always appreciated. Reread the documentation for QProcess:start(). The program to be run and its arguments are separate. Something like this: process.start( "/path/to/docker.exe", QStringList() << "exec" << "-it" << "xunxiao" << "/bin/bash" ); Your attempt to call CD will not work. CD is a Windows command shell builtin and there is no separate executable to run. Your attempt to run ls seems doomed to fail on Windows.
  • This topic is deleted!

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

    Unsolved
    1
    0 Votes
    1 Posts
    4 Views
    No one has replied
  • read data continuously from QProcess

    Unsolved
    16
    0 Votes
    16 Posts
    2k Views
    jsulmJ
    @mranger90 said in read data continuously from QProcess: I'm not the one with the issue Oh, I also did not realise :-D
  • This topic is deleted!

    Unsolved
    7
    0 Votes
    7 Posts
    77 Views
  • the difference between QDataStream and QFile

    Unsolved
    3
    0 Votes
    3 Posts
    305 Views
    Paul ColbyP
    Hi @jgxy1123, And the problem is the final number of bytes written to the file will be a little more than 10000bytes. Which is correct - it should be more than the 10000 bytes of data. As @jsulm indicated, and per the docs, QDataStream is not raw data, but rather: A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order. ... To take one example, a char * string is written as a 32-bit integer equal to the length of the string including the \0 byte, followed by all the characters of the string including the \0 byte. When reading a char * string, 4 bytes are read to create the 32-bit length value, then that many characters for the char * string including the \0 terminator are read. The exact format will depend on which QDataStream::operator<<() overload is being chosen by the compiler based on your actual code, but the the resulting stream will include things like length indicators, and, possibly have its endianness reversed, depending on the host CPU, etc. Cheers.
  • Run docker command by qt button

    Solved
    2
    0 Votes
    2 Posts
    176 Views
    jsulmJ
    @azys233 said in Run docker command by qt button: I want to press a "start" button Where? Do you mean you want to write a Qt application where you can press a button to execute "docker exec"? If so, where exactly do you need support? Use QPushButton and https://doc.qt.io/qt-6/qprocess.html to execute external processes.
  • Wait for a signal which carrying a specific argument

    Moved Unsolved
    2
    0 Votes
    2 Posts
    244 Views
    S
    Most likely not. It is certainly possible to write a template template <class Func1, class Func2> void waitForTimeout(QObject* sender, Func1 signal, Func2 predicate, int msec) and call it with waitForTimeout(this, &MyClass::triggered, [&](int i){...}, msTimeout);. However, the predicate cannot reference the loop because it cannot capture it. Possibly there is a workaround that you could also provide an additional signal which will be connected to loop.quit(). This signal could be captured by your predicate lambda and thus emitted. Another approach could be to make it a class waitForTimeout_t. Then I would probably store the predicate as a std::function. This would allow a 2-step approach with a constructor and member functions: waitForTimeout_t waiter(this, &MyClass::triggered, [&](int i) {}, msTimeout); // just a dummy lambda to get the type right for std::function waiter.setPrecidate([&](int i) { if(i == 123) waiter.getLoop().quit(); }); waiter.wait(); In simple cases you could directly write: waitForTimeout_t(this, &MyClass::triggered, [&](int i) {...}, msTimeout).wait(); It would be little annoying to always have to write wait(), though. One other disadvantage would be that I would assume that the last few lines (if(time.isActive())...) would be per specific use cases. With my first suggestion the template function waitForTimeout(...) could just return a bool which tells you if the timer did fire. The thing is that this approach should not be your goto solution. Nested loops are considered evil in Qt. Nothing is preventing you from becoming deeply nested. Qt documentation itself discourages using nested loops. They should be rarely used. Thus, it is best to not write a template for this because it would encourage using this approach.
  • Signals and Slots, processing order

    Unsolved
    8
    0 Votes
    8 Posts
    609 Views
    Christian EhrlicherC
    @SimonSchroeder It was not documented in Qt5, then a discussion on the ml and then this was added: https://doc.qt.io/qt-6/signalsandslots.html#signals (but it seems to be backported to Qt5). But I must admit it's a little bit to generic as it does not cover the queued-connection case where it's not defined. Even though it's on-order when passing all from one to another thread since the events are added to the receivers event queue.
  • How to change title in installation?

    Unsolved
    3
    0 Votes
    3 Posts
    235 Views
    Y
    @JonB thanks.
  • Project ERROR: failed to parse default search paths from compiler output

    Unsolved
    2
    0 Votes
    2 Posts
    212 Views
    SGaistS
    Hi, You need to apply the patch linked in QTBUG-117747.
  • QML RowLayout spacing

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

    Unsolved
    1
    0 Votes
    1 Posts
    6 Views
    No one has replied
  • SQLite (Drill Down example)

    Unsolved
    2
    0 Votes
    2 Posts
    181 Views
    C
    @Flaming-Moe When you construct a QSqlQuery without any arguments, or with only a query string, then the database argument defaults to an invalid QSqlDatabase object. In this circumstance the query object will be associated with the default database, i.e. the QSqlDatabase object returned by QSqlDatabase::database().
  • How to get "ProductName" and "ProductVersion" properties for a DLL file?

    Unsolved
    4
    0 Votes
    4 Posts
    1k Views
    Chris KawaC
    @Urbi You seem to be running your app as non UNICODE and passing wide character functions to the WinAPI calls. Either make sure you define UNICODE in your project or explicitly use wide versions of the functions e.g. GetFileVersionInfoSizeW instead of GetFileVersionInfoSize.
  • closeEvent and focus

    Unsolved
    15
    0 Votes
    15 Posts
    2k Views
    Chris KawaC
    @james-b-s Starting an event loop in closeEvent won't work. You're already in an event handler and you need to get back from it for the dialog to function properly. You can do what @JonB said - delay closing until you process your focus loss. For example use a QDialog derived class like this: class MyDialog : public QDialog { bool allowClose = false; public: using QDialog::QDialog; void closeEvent(QCloseEvent* evt) override { if (!allowClose) { evt->ignore(); // don't close and let event loop handle focus loss allowClose = true; // let it close next time setFocus(Qt::OtherFocusReason); // switch focus to something else, e.g. this or cancel button QTimer::singleShot(0, this, &MyDialog::close); // schedule another close event } else { askUserToSaveStuff(); QDialog::closeEvent(evt); } } };
  • QCursor::pos() only works correctly if I change the Qt Creator theme.

    Solved
    12
    0 Votes
    12 Posts
    1k Views
    P
    @Christian-Ehrlicher I disable Wayland in /etc/gdm3/custom.conf and reboot Ubuntu, everything worked correctly. Thanks for the help!
  • getting Qpainter error while settext for qlineEdit(urgent)

    6
    0 Votes
    6 Posts
    441 Views
    Christian EhrlicherC
    @Gokul2002 said in getting Qpainter error while settext for qlineEdit(urgent): If possible is there any other solution please let me know. https://doc.qt.io/qt-6/signalsandslots.html
  • How do I Build this Widget for Automotive Application in GUI

    Solved
    11
    0 Votes
    11 Posts
    920 Views
    M
    @JonB Thank You