Skip to content
  • Qlist returns Size as -1

    Unsolved General and Desktop
    11
    0 Votes
    11 Posts
    3k Views
    ?

    @Mathan-M Ok, then have a look at my code above; that works as expected, what's different to your code?

  • 1 Votes
    13 Posts
    14k Views
    pauleddP

    Thank you for the hints, I think I now have enough information to solve it.

  • 0 Votes
    24 Posts
    24k Views
    QjayQ

    I too was also thinking of full rewrite but i don't have much time for that right now :/ .

  • 0 Votes
    6 Posts
    2k Views
    M

    @kshegunov said:

    You're missing the fact that QWidget and its descendants aren't reentrant.

    Actually, I missed more than that... I completely miss the fact that, when dealing with QWidget or simillar + threads, that exactely when I should have used signal/slot mechanism... I feel dumb about it, but anyway, the Crawler object now crawls using Qt::Concurrent and send a signal with the text to add to the QListWidget, and then a MainWidget's slot is called to create and add the item.

    Thanks for your help

  • 0 Votes
    5 Posts
    2k Views
    mongrelmacM

    I see. Thanks @raven-worx @SGaist!

  • 0 Votes
    3 Posts
    2k Views
    L

    @Chris-Kawa Sorry for getting you into a mistake and for leaving my problem without any further explanation. So, the variable intArray is just a simple Qlist, i forgot to change its name before posting so please, excuse me for that.

    For index, it looks like index = w * 4, and after that, there is value = qRgba(intArray[index-3], intArray[index-2], intArray[index-1],intArray[index]);

    I know that if the length of my text is not divisible, it's not gonna work. And here the Qlist come in handy. I can check if this number is divisible by 4 and if yes, the code goes as it is now, but when it's not I wanted to add as many items equal to 0 as I need to make it divisible.

    Does my explanation makes any sense? I will try try to explain it like that :

    if (number is divisible by 4) {
    here comes my algorithm for making this image
    }
    else
    {
    add as many number as it is needed to make it divisable to qlist and then run the algorithm
    }
    But then those error appeared and I don't really know how can I get rid of them :/

    But, how could I make it with vectors? Would it be faster or safer than by using Qlist?

    Thanks a lot for help!

  • QList index

    Solved General and Desktop
    16
    0 Votes
    16 Posts
    6k Views
    W

    @Chris-Kawa

    Got it ;)

  • 0 Votes
    22 Posts
    10k Views
    A

    @micland

    WOOW!!! Thank you sooo much micland!! It works!!!
    I tried a code similar to yours but some data were missing. Just needed to do a very tiny modification on your code:

    qDebug() << key << value.variant().toString();

    or directly

    qDebug() << value.variant().toString();

    Except it, it is perfect! Thank you again.
    @micland said:

    I have no clue why the qdbusviewer of Qt 5.6 is unable to call the DBus method but the code snippet above is working fine.

    I hope it is going to change as I intend to use it or the 5.7 version very soon.

    Cheers again.

  • 0 Votes
    15 Posts
    14k 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
    5 Posts
    7k Views
    FerniF

    I'm such a newbie programmer :(
    I study electronics engineer and I like programming but I don't receive a good foundation in my university and I had to learn a lots of things by myself. Also, I haven't done any OOP for years and I'm new in Qt.
    Many many thanks!! I will pay more attention to my coding :)

  • 0 Votes
    3 Posts
    3k Views
    Hannes TH

    @mrjj Thank you a lot, it works!!!

  • 0 Votes
    3 Posts
    2k Views
    A

    However I did certainly what you said that was only little part.
    Thank for your answer, without it I would only find a way around this issue probably. (like 2 parallel QLists)

    So what works?

    I make additional QObject with parent "this (list of lists)". Then I make it parent of every QObject I want to delete (QObjects with list and QObjects within lists). I don't change CppOwnership. After that I clear() list and add new QObjects (obsolete QObjects stay accessible as children of that additional QObject). After final emit I delete that QObject with deleteLater(). QPointer isn't necessary here I think. I tried deleteLater in another way of doing things and it crashed, so that is the only way I found. My application deletes QObject and all children with it. With neither crash or leak. QObject * delQObject = new QObject (this); set_parents_list(delQObject ); m_list_of_listQobjects.clear(); for () m_list_of_listQobjects.append(new listQobject); emit m_list_of_listQobjectsChanged(m_list_of_listQobjects()); delQObject->deleteLater();

    where:

    listoflistsofQObjects :: set_parents_list(QObject * parent) { for (int i = m_list_of_listQobjects.count(); i>0; i--) { m_list_of_listQobjects[i-1]->setParent(parent); m_list_of_listQobjects[i-1]->set_parents_list(parent); } }

    Following function isn't necessary if QObjects already have parent that is deleted (like listofQObjects or some QObject inside it). It's safer to make elements children, because then one doesn't need to call deletes in destructor.

    listofQObjects :: set_parents_list(QObject * parent) { for (int i = m_list_ofQobjects.count(); i>0; i--) { m_list_ofQobjects[i-1]->setParent(parent); } }

    I don't know if is it "right way", I even found here somebody uses my earlier version with additional list (but it's unsafe for sure).

    The best explanation how to manage memory in qt I found here.

    If there is better way to do so, please share.

  • Problem with QList

    Solved General and Desktop
    5
    0 Votes
    5 Posts
    2k Views
    SGaistS

    Hi,

    There's usually no need to allocate QList nor QStringList on the heap. Do you have any reasons to do that ?

  • 0 Votes
    7 Posts
    3k Views
    SGaistS

    When using a custom model, the usage is to add specialized methods to your model to add/remove your custom objects. So when you add/remove a Shape you know exactly where they are so you can use beginInsertRow/endInsertRow and the update will happen automatically for you.

  • 0 Votes
    6 Posts
    3k Views
    SGaistS

    Rather than going up-front with building your own GUI for a painting program, I'd recommend taking a look at what is currently existing like Krita or KolourPaint. Painting is a vast subject that can cover many aspects. Just take a look at Qt's examples on the subject.

    You should also take the time to look at QtQuick for the GUI design part.

  • 0 Votes
    8 Posts
    4k Views
    Joel BodenmannJ

    @Asperamanca
    I am actually not sure anymore. I thought that there was an issue regarding the boundingRect() implementation but I have changed my design since then. I will give this another thought.

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    Well, your model should then return one column and the string list size as row count. Then data should return the appropriate string from the list

  • 0 Votes
    3 Posts
    3k Views
    P

    It's been solved. "this" pointer was null, thus it was crazy debugging.

  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    Hi,

    Do you mean move them at the right position ?

  • 0 Votes
    1 Posts
    708 Views
    No one has replied