Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k Topics 456.4k Posts
  • Real confusion about when to delete QNetworkReply object

    Solved
    31
    0 Votes
    31 Posts
    3k Views
    H
    @SGaist you can use dynamic properties to keep everything in one place Didn't understand what you meant use a QMap to store the reply specific data that you will then grab in your lambda Could you provide a minimal sample code on how to do that
  • Clear background when implementing drawBackground

    Solved
    9
    0 Votes
    9 Posts
    1k Views
    M
    That's interesting that the setBackground(QBrush()) works for you. Looking at the code, QGraphicsScene::drawBackground() doesn't do anything when the background brush is Qt::NoBrush (which is what QBrush() is). Not sure what Q_D(QGraphicsScene) does; it's called at the beginning of many QGraphicsScene methods but I didn't see where it was defined. This is the code from Qt 5.12: void QGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) { Q_D(QGraphicsScene); if (d->backgroundBrush.style() != Qt::NoBrush) { if (d->painterStateProtection) painter->save(); painter->setBrushOrigin(0, 0); painter->fillRect(rect, backgroundBrush()); if (d->painterStateProtection) painter->restore(); } }
  • Is it possible to open QtVirtualKeyboard by code?

    Solved
    3
    0 Votes
    3 Posts
    267 Views
    Y
    @raven-worx Thank you once again, this solution was spot on :-) Kind regards, Yina
  • How to pass SIGNAL parameter(s) to SLOT as SAME parameters ?

    Unsolved
    2
    0 Votes
    2 Posts
    278 Views
    Chris KawaC
    SIGNAL(currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)) This code is not valid. You don't pass parameter names to SIGNAL macro, only the types. It should be SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)) how does SIGNAL process (...) parameters SIGNAL macro just stringifies the function name and parameters, so if you have a void something(int) signal it creates a string in a unified format like "2something(int)" (just an example, the actual format of that string is internal and not important to you). Same goes for the SLOT macro. Internally connect uses these strings to match function signatures. If, for educational reasons, you're curious what the format of that string is you can just write it out: qDebug() << SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)); how does SIGNAL (...) acquire parameters and HOW to pass them to slot . The code that emits that signal just passes them, so for example some function in the QListWidget will have: void QListWidget::something() { ... QListWidgetItem* current = ...; QListWidgetItem* previous = ...; emit currentItemChanged(current, previous); ... } Emiting a signal like emit someSignal(42) is conceptually something like this (in pseudo code). This is what moc generates as the function body of that signal: void someSignal(int param) { foreach (connected_slots) { if (stringified_signature_of_signal matches stringified_signature_of_slot) slot(param); } } can I envision these parameters as some kind of global variable ? I'm not sure what you mean. You're getting them in the slot so you can see them there. If you want to inspect them before the signal is emitted just set a breakpoint where the signal is emitted. In your example you ignore signal parameters. If you want to inspect them in the slot you need to change the slot signature to receive them: void testSlot(QListWidgetItem * current, QListWidgetItem * previous) and change your connect statement accordingly to use SLOT(testSlot(QListWidgetItem*, QListWidgetItem*))
  • Reading xml file using Qdomdocument, chlidnode count not coming correct

    Solved
    7
    0 Votes
    7 Posts
    806 Views
    N
    yes, i understood thanks
  • Where is QLineEdit's text drawn in QStyle?

    Unsolved qpalette qstyle
    3
    0 Votes
    3 Posts
    853 Views
    CJhaC
    @mrjj Thanks, it seems like odd behaviour. So, it uses its native palette, i.e. the palette set either directly or inherited from its parent. I am able to change the colour now, but I am using a C-Style cast, and that's why I am not sure if I should do it. Here is my solution: void GuiStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const { if(vars[id].customTheme) { if(element == QStyle::PE_PanelLineEdit) { const QStyleOptionFrame* comboOption = qstyleoption_cast<const QStyleOptionFrame*>(option); QStyleOptionFrame newComboOption = *comboOption; newComboOption.palette.setBrush(QPalette::Base, Qt::red); // I am using C-Style cast to get the widget in a non-const pointer and then it's palette again the same way QLineEdit* lineEditPtr = (QLineEdit*)widget; QPalette pal = (QPalette)lineEditPtr->palette(); pal.setColor(QPalette::Text, Qt::green); lineEditPtr->setPalette(pal); QProxyStyle::drawPrimitive(element, &newComboOption, painter, widget); } } else { QProxyStyle::drawPrimitive(element, option, painter, widget); } }
  • build in linux

    Unsolved
    2
    0 Votes
    2 Posts
    237 Views
    JonBJ
    @Mc6bullet Are these entries you have created yourself, or something from Qt? If from Qt then presumably something needs configuring to use Linux commands instead. If your own: in a Windows Command Prompt type xcopy /? to understand its existing usage. Then translate to the equivalent in Linux. I would suggest you might need to use rcp, or perhaps cp -r will suffice. Use man rcp or man cp to see their usages.
  • Why i am gettting error: 'QtMsgHandler' does not name a type' ?

    Unsolved
    9
    0 Votes
    9 Posts
    437 Views
    Q
    @Christian-Ehrlicher Sorry for trying that.
  • setStyleSheet via .qss file

    Solved
    5
    0 Votes
    5 Posts
    2k Views
    E
    @jsulm With resource file it is working thanks.
  • i want to on and off this log at runtime how to achieve this thing efficiently in qt ?

    Locked Unsolved
    2
    0 Votes
    2 Posts
    145 Views
    Christian EhrlicherC
    Please write a proper question - closed!
  • Change property of a class during runtime

    Unsolved qstyle qspinbox
    1
    0 Votes
    1 Posts
    260 Views
    No one has replied
  • How to add log4j library in qt ?

    Solved
    3
    0 Votes
    3 Posts
    266 Views
    Q
    @jsulm Is there any logger system is there like log4j in qt whose log i can on and off in file as per my need ?
  • get the return value of the emitted signal

    Solved
    11
    0 Votes
    11 Posts
    882 Views
    KroMignonK
    @ekato993 said in get the return value of the emitted signal: I know about lambdas but how to pass the string? Perhaps you are aware about lambdas but that is not the question here. You have to learn signals/slots usage, because it is a very important concept in Qt world. So if you want to build applications with Qt, take time to learn: what QObject are => https://doc.qt.io/qt-5/object.html what QObject parent <=> child relation chip => https://doc.qt.io/qt-5/objecttrees.html how signals/slots works => https://doc.qt.io/qt-5/signalsandslots.html Those are the minimum to be comfortable with Qt development. This will save you many hours of frustration and headaches! It is up to you to learn, the documentation is freely available.
  • Windows 10 QDir::separator

    Unsolved
    5
    0 Votes
    5 Posts
    380 Views
    O
    Not question related, but this line: @SPlatten said in Windows 10 QDir::separator: if ( strPath.endsWith(chSeparator) != true ) will be better in this way: if ( !strPath.endsWith(chSeparator) )
  • How to overlay a button over QAxWidget?

    Unsolved
    1
    0 Votes
    1 Posts
    97 Views
    No one has replied
  • 0 Votes
    2 Posts
    143 Views
    jsulmJ
    @kenchan What library are you trying to load?
  • Connect signals and slots of a class from another class

    Unsolved
    16
    0 Votes
    16 Posts
    962 Views
    CP71C
    @thewiggin said in Connect signals and slots of a class from another class: Here's my workaround, it seems needlessly complex and has me begging the question of if its possible to connect to the slot of another class outside that class. All the declarations I can find use "this" as the third augment. Yes of course! you see "this" because normally the sender or/and the receiver is the class itself, but you can connect one or two classes that arent the classe itself! But this you already see in your last post!
  • qtcreator.exe - Bad Image .dll problems

    Unsolved
    11
    0 Votes
    11 Posts
    3k Views
    mrjjM
    @borhanreo Hi and welcome to the forums The Image didnt show up and is generally broken here. use something like postimage.org and the Direct link.
  • how to convert text into speech or vice versa

    Unsolved
    12
    0 Votes
    12 Posts
    782 Views
    jsulmJ
    @UG-SEP Google says: https://download.qt.io/new_archive/qt/5.8/5.8.0/
  • QDocument has not expected behavior when creating elements

    Solved
    7
    0 Votes
    7 Posts
    300 Views
    A.v.OA
    @JonB said in QDocument has not expected behavior when creating elements: And in this case the setAttributeNode() docs show it returns the attribute node it is replacing, or a dummy node, and that's what you setValue() `on. Qt's stuff does work and as documented so not unexpected, just not to the chaining expectations you have have from, say, jQuery or whichever XML DOMs. You are right the QDomElement::setAttributeNode() does indeed not return a copy but a null attribute. Manual on QDomNode::insertAfter(...) states: Returns a new reference to newChild on success or a null node on failure. The DOM specification disallow inserting attribute nodes, but due to historical reasons QDom accept them nevertheless. My first interaction was the PHP XML Dom setAttribute(...) where the manual says: The new DOMAttr or false if an error occurred. Where I'm used to chain functions. Looking to the Java implementation, which I never worked with, does the same as Qt's implementation. Chaining makes it easy because local variables are superfluous in that case and for me it is more readable. Conclusion: My assumption was apparently incorrect.