Skip to content
  • autodelete pointer QList

    Unsolved General and Desktop qlist pointer delete
    4
    0 Votes
    4 Posts
    1k Views
    F
    @ChrisW67 Thank you! Yes, I thought about smart pointers as well but I am (yet) not very familiar with it and don't know which one is correct. Currently we work most of the time with raw pointers and the old Qt3 QPtrList . Maybe the qt-version: https://forum.qt.io/topic/19073/any-difference-between-std-shared_ptr-and-qsharedpointer/2 could be an option as well...
  • 0 Votes
    2 Posts
    364 Views
    R
    One more example: #include <QCoreApplication> #include <iostream> #include <QMetaObject> #include "example.h" #include <QDebug> #include <QMetaProperty> #include <QPointer> void gadgetExplorer(void *ptr, const char* s) { //Receives Player and access its meta-object int typeId = QMetaType::type(s); const QMetaObject *mo = QMetaType::metaObjectForType(typeId); qInfo() << "Q_GADGET: " << mo->className(); QMetaProperty mp; for(int i = 1; i < mo->propertyCount(); i++) { mp = mo->property(i); qInfo() << "Q_PROPERTY: " << mp.typeName() << "Value: " << mp.readOnGadget(ptr); if(int(mp.type()) == 1024) gadgetExplorer(ptr, mp.typeName()); } } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qRegisterMetaType<Player>(); qRegisterMetaType<P2D>(); qRegisterMetaType<P2D*>(); Player p1; p1.setSpeed(30); p1.p2d = new P2D(); p1.p2d->setX(10.0); p1.p2d->setY(25.0); gadgetExplorer(&p1, "Player"); return a.exec(); } gadgetExplorer() works fine for the first Q_GADGET, but for the second one the read property doesn't work. Is it possible to access the second's Q_GADGET pointer?
  • Pointer to a Q_GADGET

    Solved General and Desktop meta-objects pointer function qobject qgagdet
    3
    0 Votes
    3 Posts
    822 Views
    R
    @VRonin Solved! Thanks for your time!
  • 0 Votes
    7 Posts
    3k Views
    K
    @SpaceToon said in Check if a pointer was deleted in Qt for GUI Application: Thank you very much, that worked! Do you mean just replacing delete with deleteLater()? It would be discoveryAgent->deleteLater(); Check out the documentation under the given link in my post.
  • 0 Votes
    5 Posts
    2k Views
    SGaistS
    Which one do you mean ?
  • 0 Votes
    14 Posts
    4k Views
    mrjjM
    @Lanparty said in Application crashes while accessing Pointers and while Hovering over custom QGraphicsItems: btw: how do I change the status of my post to "solved"? First post, Topic Tools button to the side.
  • 0 Votes
    5 Posts
    5k Views
    SGaistS
    @oblivioncth said in std::unique_ptr with QObject derived class?: Won't let me mark your post as the answer for some reason. Sorry. Done for you :)
  • 0 Votes
    4 Posts
    2k Views
    mrjjM
    Hi Just a note first Having class SerialPort : public QObject and then QSerialPort *serialPort; Where only diffence is capital S to the main class is just confusing. anyway, why is the issue with settings(new SettingsDialog()), did you declare it as void settings(SettingsDialog *mydialog) Im not sure what you dont understand. To use a pointer to a class in another class, you simply give the pointer to the other class and it can use it class B {}; class A { B* mykeptBpointer; setB(B* myb) { mykeptBpointer = myb; } void DoB { mykeptBpointer->xxxx(); }; A mya; B* myb = new B; mya.setB(b); oh, is settings(new SettingsDialog()) rather settings = new SettingsDialog();
  • QList<QObject*> and Memory Leak Issue

    Solved General and Desktop memory leak qlist qobject pointer
    15
    0 Votes
    15 Posts
    15k Views
    DongD
    @kshegunov There is a reason why I can't use QT Property Binding (It only support predefined Property using Q_PROPERTY script). Please take a look at my topic about Auto Binding 2 ways with Dynamic Property But Binding is an other topic. About "Object's pointers & Memory" I also take an advise from a Pro in C++ & memory management. His solution is implement a Factory Pattern to Create/Delete Object's pointers (also free memory when an instance had no pointer to it.) (I think I'll give it a try)
  • 0 Votes
    4 Posts
    2k Views
    M
    Mayby try using Qt's signal slot system: //A->reciver //B->sender //B signals: void B::newData_ready(QString data); //you have to pass apropriate type, assuming QString since it is from QLineEdit slots: void B::on_SendButton_clicked() { emit newData_ready(userData_LineEdit->text()); } //A slots: void A::on_newData_ready(QString data) { QTableWidgetItem *item = new QTableWidgetItem(data); //here add item where u want } connect(B, SIGNAL(newData_ready(QString)), A, SLOT(on_newData_ready(QString))); Just a scheme so it probably wont work like that but I hope you get the point.
  • QThread and pointers

    Solved General and Desktop qthread pointer
    12
    0 Votes
    12 Posts
    6k Views
    kshegunovK
    @beecksche said: The advatage of a QScopedPointer is that you don't have to care about the destruction of the object, right? Yes. It's a thin wrapper around the raw pointer and will delete the held reference when it goes out of scope. The idea is to use the stack based QScopedPointer object to manage the heap-allocated object it's referencing. Kind regards.
  • Compose pointer to property of object

    Solved General and Desktop c++ pointer objects properties
    25
    0 Votes
    25 Posts
    10k Views
    McLionM
    Got it solved :-) QWebFrame * webGUIframe = qobject_cast<QWebFrame >(sender()); QWebView * webGUI = (QWebView)(webGUIframe->parent())->parent(); webGUI->page()->mainFrame()->addToJavaScriptWindowObject("NativeBridge", this);
  • 0 Votes
    6 Posts
    4k Views
    K
    @kitfox Figured it out. The Q_PROPERTY in Enviroment had the wrong data type.
  • 0 Votes
    4 Posts
    3k Views
    L
    Hello, Both inputs are highly appreciated. I understand better how, when and why should I choose pointers over refs. I'm still reading some stuff here and there on how to produce some good code. Memory management has always been a doozy matter in C++ and i just can't get this Stroustrup quote out of my head : "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off. ". Thanks again for replying so quickly, I will apply everything i've learned here on my work asap. Best regards.
  • 0 Votes
    4 Posts
    2k Views
    L
    Why parent ptr? Parent child relationship - http://doc.qt.io/qt-5/objecttrees.html
  • 0 Votes
    6 Posts
    2k Views
    C
    @SGaist Ok, I just tried to rescaled my image array within an intensity between 0 to 255 and cast a uchar*, it's working now. Thanks
  • 0 Votes
    4 Posts
    2k Views
    A
    If your question was how to initialize QObject from child you do not need extra Parent variable, no extra deletes, just add it in constructor: Contact::Contact(int cat,QString fir,QString lst,QString ad,QString zp, QString ct,QString nm,QObject *parent) ::QObject( parent ) { .......... }