« first day (849 days earlier)      last day (2228 days later) » 
00:00 - 23:0023:00 - 00:00

23:02
Ok im back -.- can any1 let me know why this does not produce 20 where the comments are but I get 10 and 20 ? Well I know its a copy of object, but how do I NOT make a copy of object? I get 3x destructor called on the test node
    class testNodeX {
    public :
        testNodeX() {};

        ~testNodeX() { std::cout << "Im getting deleted" << std::endl; }

        int x;
    };
int main() {
    testNodeX x1;
    x1.x = 10;
    std::shared_ptr<testNodeX> a1 = std::make_shared<testNodeX>(x1);
    std::shared_ptr<testNodeX> a2 = std::make_shared<testNodeX>(x1);
    std::cout << x1.x << std::endl;
    a1.reset();
    a2->x = 20;
    std::cout << x1.x << " This should return 20"<<std::endl;
    std::cout << a2->x <<" This should return 20"<< std::endl;
something tells me this is not possible ;c
std::shared_ptr<testNodeX> a1 = std::make_shared<testNodeX>(x1);
std::shared_ptr<testNodeX> a2 = a1;
this should work
I cant do a2=a1
I dont have a1 to use it, I have Raw pointer... (thanks qt)
sure you can
perhaps post your real code
    icTreeNode *node = static_cast<icTreeNode *>(index.internalPointer());
    nodePtr = std::make_shared<icTreeNode>(*node);
the nodePtr is a copy, esentially a new item.
I mean
its weird
internalPointer return void*
nodePtr = std::make_shared<icTreeNode>(static_cast<icTreeNode *>(index.internalPointer()));
23:10
so if my node is a shared_ptr<> it should be shared_ptr
note: see reference to function template instantiation 'std::_Ref_count_obj<_Ty>::_Ref_count_obj<icTreeNode*>(icTreeNode *&&)' being compiled
        with
        [
            _Ty=icTreeNode
        ]
note: see reference to function template instantiation 'std::shared_ptr<_Ty> std::make_shared<icTreeNode,icTreeNode*>(icTreeNode *&&)' being compiled
        with
        [
            _Ty=icTreeNode
        ]
and also this one for some reason
error C2664: 'icTreeNode::icTreeNode(const icTreeNode &)': cannot convert argument 1 from '_Ty' to 'const QString &'
        with
        [
            _Ty=icTreeNode *
        ]
okay, I'm out of here, I can't help with this
sorry
:- )))
its ok
can I cast in to shared_ptr?
you just tried, didn't you?
like static_cast<std::shared_ptr<icTreeNode>>(internalPointer) ?
holy f**k... well, you can try, but I'm not touching that
23:16
XD
no matching conversion from void* to std::shared_ptr<icTreeNode>
it nodeptr also a shared_ptr<icTreeNode>?
you mean internalPointer?
inline void *internalPointer() const Q_DECL_NOTHROW { return reinterpret_cast<void*>(i); }
no
nodePtr <--- that
std::shared_ptr<icTreeNode> nodeptr
isn't there any documentation about ictreenode?
23:19
wait
why wont I just use std::static_pointer_cast O_O
i made icTreeNode
its mine :D
hmm
I could actually
just store shared_ptr inside the node itself!
fuck -.-
try something along the lines of std::shared_ptr<T>(static_cast<T*>(r.get()))
wait, you already did ^^
:- )
I think I'll store the shared_ptr<> inside the node itself
and just retrieve it from there...
it would solve all the issues
I don't think that's a good idea
cant think of anything else
unles you know how I can cast void* in to shared_ptr<>
wait
google !
time for you to go information hunting
lol
23:25
:D
    std::shared_ptr<icTreeNode> kl = *static_cast< std::shared_ptr<icTreeNode> * >(index.internalPointer());
doesn't look like that could work
why?
for one thing you don't convert a raw pointer to a shared_ptr like that
besides, how did you make icTreeNode? is it inherited from somewhere else?
index.internalPointer() returns pointer to object, which means its a pointer to shared_ptr, which mean that I have to cast it to raw ptr to shared_ptr<> and then just deraw pointer it
no
its class icTreeNode()
23:29
yup
then why not do shared_ptr<QModelIndex>?
since that's the type you get from internalPointer
I didnt subclass modelIndex
only QAbstractItemModel/QTreView and added my own node as tree viewnode
qt creates/manages qmodelindexes by itself
and I think it takes my data structure, which is shared_ptr<icTreeNode> by default
so it holds a pointer to that object
well
you THINK, but you have no idea what happens
gonna test it
xD
you need to find out
23:32
testing it now
:D
it almost works! :D
IT WORKS
FUCKING NAILD ITTTTTTTTTTTTT
WOHOOOOOOOOOOOOOOOOOOO
Ure legend Miroslav thanks! If it was not for u nudging my brain I would not get it :D yayyyyy xD
uh uh, did you actually run the program?
yea
I gotta go and replace rest of the functions
but the 2 I was testing
so you actually cast void* to a shared_ptr?
were crashing
now they work :D
yep
huh, interesting
23:35
QModelIndex holds a void* object;
so its a pointer to shared_ptr()
Returns a void * pointer used by the model to associate the index with the internal data structure.
and since I gave it shard_ptr<icTreeNode> as my data structure
all it did was void*obj = &myNode
My somebody is "misusing smart pointer" sense is tingling
hahahahahahhaahhaha
Qt pointers are owned by their parents, don't wrap them in a reference counter. You should not use any smart pointers with qt objects, as the parent is supposed to delete them.
the object is not qt object
its my own class
not subclasing anything of qt
damn whoever designed the qt treeview/abstractmododel system is a genius
Okay then don't use pointers.
23:40
@Dariusz I think, looking at this std::shared_ptr<icTreeNode> kl = *static_cast< std::shared_ptr<icTreeNode> * >(index.internalPointer()); your problem was that you passed a pointer to a shared_ptr
you are NOT supposed to pass a pointer to shared_ptr, just shared_ptr itself
I didnt
qt did it
lol, really?
when qt created QModelIndex
Lol what
it passesd a pointer to object
which mean it passed a pointer to a shared_ptr
23:42
man, I don't know why you decided not to subclass from Qt, this is going to give you serious headaches later on
not to subclass what?
QStandardItem ?
What are you trying to do?
I don't know what, but I know that you are trying to do the work Qt is supposed to do in the first place (managing memory)
The code you posted at the top looks like its recreating the wheel, which would trigger any outside observer
I build custom treeView from ground up. I tried using standard qt widgets but they had bugs and failed at logic. So it was teh only way to do it without changing qt source
23:43
I don't believe you
well I posted it on qt bug tracker and they marked it, but havent fixed yet (after a year)
so I had to make my own system
Okay but the qobjects you should it build it with have very well defined child/parent relationships
yeh but my treeItem is not qobject
@Dariusz that's the problem, I guess
when you subclass qabstractitemModel, you have to reimplement virtual functions, and thats where I returned the objects qt ask for, like row count/child/etc/etc so qt is able to use MY OWN data structure, for displaying my data. I have to manage memory of these objects myself tho
and since now, all of these objects are going to be shared-ptr<> and not raw* I'm fairly sure I'll have even less issues now o.O
or more o.o
23:47
well, good luck, I'm out
im fairly sure I will be back in like 2 years being like "How do I clean up my objects ?! I have memory leaks everywhere @_@" ahahahaha
You can, for example, not use pointers.
:- )
Or wrap a tree implementation from. Boost
Im good with qt now I think
23:51
Link me the bug
No longer relevant as I have my own tree structure. But it was quite "fun" time back in the day when I was learning qt... huh... good ol days :D
00:00 - 23:0023:00 - 00:00

« first day (849 days earlier)      last day (2228 days later) »