Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.5k Posts
  • [SOLVED] how to print a int and string to the status bar?

    4
    0 Votes
    4 Posts
    3k Views
    K
    thank you Lukas Geyer
  • 0 Votes
    2 Posts
    5k Views
    L
    "Drop Site Example":http://developer.qt.nokia.com/doc/qt-4.8/draganddrop-dropsite.html
  • QPluginLoader, late binding and signals/slots

    17
    0 Votes
    17 Posts
    8k Views
    L
    You cannot define signals and slots in interfaces, as you would have to subclass QObject, which will result in a non-abstract class. In addition, once your interface dervies from QObject, all classes implementing this interface derive from QObject as well, which means you cannot subclass from other QObject subclasses (like QWidget), as QObject does not support multiple inheritance (this is the problem you are currently running into). The (or one) solution is to define signals and slots in the interface, but not to subclass QObject. This does not strictily enforce the implementation of those signals and slots in interface implementations at compile time, but it enforces the implementation of the (ordinary) methods and clearly states that they have to be signals and slots in interface implementations. Signals and slots are resolved during runtime and as long as interface implementations subclass any QObject subclass they can be used. @ class SampleInterface { // Delcaring those methods as signals and slots does NOT enforce // that they are actually implemented as signals and slots in interface // implentations, but it forces at least an implementation of ordinary // methods and indicates clearly that those methods should be // implemented as signals and slots. QMetaObject (or connect()) can // be used to check if they have been actually implemented as signals // and slots during runtime. signals: virtual void sampleSignal() = 0; public slots: virtual void sampleSlot() = 0; }; Q_DECLARE_INTERFACE(SampleInterface, "SampleInterface") class SampleQObjectImplementation : public QObject, SampleInterface { Q_OBJECT Q_INTERFACES(SampleInterface) signals: void sampleSignal(); public slots: void sampleSlot() { qDebug(Q_FUNC_INFO); emit sampleSignal(); } }; Q_EXPORT_PLUGIN2(sampleQObjectImplementation , SampleQObjectImplementation) class SampleQWidgetImplementation : public QWidget, SampleInterface { Q_OBJECT Q_INTERFACES(SampleInterface) signals: void sampleSignal(); public slots: void sampleSlot() { qDebug(Q_FUNC_INFO); emit sampleSignal(); } }; Q_EXPORT_PLUGIN2(sampleQWidgetImplementation , SampleQWidgetImplementation) // Connect to slots and signals using QObject as base class pointer // (as returned by QPluginLoader::instance()) QObject* sampleQObjectImplementation = new SampleQObjectImplementation; QObject* sampleQWidgetImplementation = new SampleQWidgetImplementation; QObject::connect(sampleQObjectImplementation, SIGNAL(sampleSignal()), sampleQWidgetImplementation, SIGNAL(sampleSlot())); // Cast to SampleInterface to call methods directly SampleInterface sampleInterface = qobject_cast<SampleInterface>(sampleQObjectImplementation); sampleInterface->sampleSlot(); @ Brain to terminal. Not tested. Exemplary. A variation to this idiom is to add a <code>QObject *object() { return this; }</code> method to the interface, which allows for using signals and slots with an interface pointer as well. @ SampleInterface sampleQObjectInterface = qobject_cast<SampleInterface>(sampleQObjectImplementation); SampleInterface sampleQWidgetInterface = qobject_cast<SampleInterface>(sampleQWidgetImplementation); connect(sampleQObjectInterface->object(), SIGNAL(sampleSignal()), sampleQWidgetInterface->object(), SLOT(sampleSlot())); @ Brain to terminal. Not tested. Exemplary.
  • How parent object affect painting to child object?

    24
    0 Votes
    24 Posts
    13k Views
    P
    [quote author="Volker" date="1325243008"] [quote author="pratik041" date="1325220949"] [quote author="Volker" date="1325183040"] Why do you paint yourself at all? What is wrong with the default provided widgets?[/quote] I have painted myself because this is the requirement provided to me. [/quote] And did you try to achieve your goal using standard widgets without painting yourself?[/quote] I am now getting proper output with both painting and without it also.
  • How can i get default focus frame in Mac for custom widget?

    5
    0 Votes
    5 Posts
    2k Views
    G
    Have a look at [[Doc:QFocusFrame]].
  • UDP : How to send a response to a client

    9
    0 Votes
    9 Posts
    12k Views
    G
    "QUdpSocket::readDatagram() ":/doc/qt-4.8/qudpsocket.html#readDatagram takes optional pointers to a [[Doc:QHostAddress]] for the address and a quint for the port. bq. Receives a datagram no larger than maxSize bytes and stores it in data. The sender's host address and port is stored in *address and *port (unless the pointers are 0). Use it to send your data back to the sender. In Qt, using [[Doc:QUdpSocket]] you can sort of connect between the server and the client and use [[Doc:QIODevice]]'s read() and write() methods. This is not a real connection like in using TCP, but kind of a "virtual connection".
  • Qt way to set FIFO map ?

    5
    0 Votes
    5 Posts
    3k Views
    U
    Thanks Andre , this is what i have implemented in the end
  • Set QAuthenticator values in other thread

    2
    0 Votes
    2 Posts
    2k Views
    T
    Solved this trouble @QObject::connect(nam, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), mainWin, SLOT(onProxyAuthenticationRequired(QNetworkProxy, QAuthenticator*)), Qt::BlockingQueuedConnection);@ Change type connection on [[doc:Qt::BlockingQueuedConnection]]
  • Multiple file edition

    7
    0 Votes
    7 Posts
    3k Views
    A
    Yes, sure that is possible. You can do such things, but you will need to handle the events yourself. Because you are using a QTabWidget, and that widget embeds QTabBar, subclassing isn't going to get you the events you need. You will need to use eventfilters. You can get a pointer to the embedded QTabBar using QObject::findChild<QTabBar*>. Then, you can install an event filter on it, and use any click the way you want it. I have used this technique to add features to QTabBar and QTabWidget that allow renaming tabs by double clicking them, and to make it possible to prevent the switch of a tab (to allow validation).
  • Qt - Skinning a QScrollBar with Paint Event?

    2
    0 Votes
    2 Posts
    2k Views
    J
    take a look "here":http://developer.qt.nokia.com/doc/qt-4.8/stylesheet-examples.html#customizing-qscrollbar
  • Problem in getting tooltip?

    4
    0 Votes
    4 Posts
    2k Views
    P
    [quote author="Anticross" date="1325161368"]Where do you set the tool tip? For some item on widget or else ? Do you use Abstract model or re-implement data method in standard model ?[/quote] Actually i was trying to show always the tooltip irrespective of the widget has focus or not. This was possible from the setAttribute function and some code was problem in event filter also.
  • Updating fixed window size

    4
    0 Votes
    4 Posts
    2k Views
    J
    Sounds like i was misunderstood. it seems that it is needed to change centeral widget's size hint, though.
  • OpenGL OS-X Lion 2.1 vs 3.2 context

    7
    0 Votes
    7 Posts
    4k Views
    P
    Oopppssss... Ok, so it does initialize and load the Core profile for 3.2 and it will accept my shaders, but now that I've gone to render some things nothing is showing. Seems I will need to dig a bit deeper... gah
  • Custom Widget Paint Event Too Soon?

    3
    0 Votes
    3 Posts
    2k Views
    C
    Ah. Yes indeed, through a long, convoluted series of function calls that certainly should not be calling show(). I wonder why I put that in there? Thanks for the kick.
  • How can i export my cpp code into .ui using Qt creator?

    8
    0 Votes
    8 Posts
    4k Views
    G
    [quote author="Lukas Geyer" date="1325157002"][quote author="tucnak" date="1325156407"]Open ui_*.cpp file, where * = mainwindow as example.[/quote] Do not modify any generated files.[/quote] It will not harm, as there are won't be ui_*.cpp files generated :-)
  • 0 Votes
    4 Posts
    2k Views
    A
    You don't want the widgets to be publicly accessible. Really. You don't. Just give your class that contains the widgets a proper public API to do whatever you need to show or read from that class, but do not expose the inner workings of your class to other parts of your application. It will lead to spagetti code, dependencies between unrelated parts of your application (making it very hard to track bugs, add features or change your GUI) and is generally Bad Style(TM).
  • SQLite column datatype

    3
    0 Votes
    3 Posts
    3k Views
    S
    Thanks! It works!
  • [SOLVED]How to get emitter of a signal in the slot?

    5
    0 Votes
    5 Posts
    42k Views
    G
    [quote author="Anticross" date="1325161551"]QObject::sender() will return you a pointer to signal sender when you call it from the slot.[/quote] Be aware that sender() returns a null pointer, if the slot is called directly (i.e. not using a signal/slot connection).
  • Unescaped backslashes are depreciated?

    3
    0 Votes
    3 Posts
    2k Views
    S
    Thanks that worked
  • How to update main windows from running thread , the right way

    17
    0 Votes
    17 Posts
    7k Views
    U
    Some update , after implementing the thread as worker object , i eliminated the delay in my gui , now its just works smooth. thanks andre !