-1

I am having a problem with Qt on Android. My apps works perfectly in MinGW but in Android it doesn't work. I have a Q_PROPERTY like:

  #include <QObject>

  class wolistupdate : public QObject
  {
   Q_OBJECT
   Q_PROPERTY(QList<QObject*> wolist READ wolist WRITE setWolist NOTIFY    wolistChanged)
  public:
     explicit wolistupdate(QObject *parent = 0);
     QList<QObject*> wolist() const;
     void setWolist(const QList<QObject*> &wolist);
 signals:
     void wolistChanged();
 private:
     QList<QObject*> m_wolist;
   }; 




#include "wolistupdate.h"

  wolistupdate::wolistupdate(QObject *parent) : QObject(parent)
   {

   }

  QList<QObject*> wolistupdate::wolist() const
   {
   return m_wolist;
   }

  void wolistupdate::setWolist(const QList<QObject *> &wolist)
   {
     if(wolist!=m_wolist)
     {
       m_wolist=wolist;
       emit wolistChanged();
     }
   } 

The view is updated when wolist is changed on MinGW. But if I build for Android, this doesn't work well.

dtech
  • 47,916
  • 17
  • 112
  • 190
DJ.Yosemite
  • 285
  • 4
  • 13

1 Answers1

0

It shouldn't update anywhere. wolistChanged is never emitted. Inserting objects into the list will not emit it. It will only emit if you change the actual list to a different list, but it won't emit on internal changes.

You don't need a setter function for that property, as it will always be that particular list you have as a class member. You should get rid of it. And emit the signal whenever an object is added to or removed from the list. This will force the view to update.

Q_PROPERTY(QList<QObject*> wolist READ wolist NOTIFY wolistChanged)

However, using a list of QObject * as a model is inefficient. The entire view will be recreated. You should implement a custom QAbstractListModel which has the extra functionality needed to update the view efficiently, updating only the changes instead of everything.

dtech
  • 47,916
  • 17
  • 112
  • 190
  • My code works on MinGW , emit is works.But Androdi ? – DJ.Yosemite Apr 05 '16 at 11:24
  • Read the answer again, you are just misinterpreting things. MinGW builds is GCC, Android builds are GCC, it is the same compiler. There is nothing platform specific which could result in such inconsistency. Your code is simply wrong, regardless of the compiler. – dtech Apr 05 '16 at 11:33
  • I assent for your anwswer.You are right.If I chancge my code to use QAbstractListModel , will it be run on Android ? – DJ.Yosemite Apr 05 '16 at 12:20
  • It will run on any platform supported by Qt – dtech Apr 05 '16 at 12:38
  • @DJ.Yosemite - there is an example implementation here: http://stackoverflow.com/questions/35160909/how-to-create-a-generic-object-model-for-use-in-qml/35161903#35161903 – dtech Apr 05 '16 at 18:00