Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter not working in Qt C++
    text
    copied!<p>I'm trying to filter the elements of a list by quantity using Qt. It's just that I press the filter button and nothing happens. Maybe i'm doing something wrong in the SLOT function. The filter function that I'm using works perfectly in my other program where I'm not using Qt. This is how the windows look like:</p> <p><a href="http://i.imgur.com/dKbZ50R.png?1" rel="nofollow">http://i.imgur.com/dKbZ50R.png?1</a> <code>- I uploaded the picture with the windows on imgur because I don't have 10 reputation to upload it from here.</code></p> <pre><code>void MedicineManagementGUI::openFilterWindow(){ ui.filterWindow = new QWidget; uiFilterMedicine.setupUI(ui.filterWindow); QObject::connect(uiFilterMedicine.btnFilterQuantity,SIGNAL(clicked()),uiFilterMedicine.filterWindow,SLOT(filterAllByQuantity())); ui.filterWindow-&gt;show(); } </code></pre> <p>the filter SLOT</p> <pre><code>void MedicineManagementGUI::filterAllByQuantity(){ uiFilterMedicine.medFilterList-&gt;clear(); QString quantityQString = uiFilterMedicine.txtQuantity-&gt;text(); int quantity = quantityQString.toInt(); List&lt;Medicine*&gt; filtered = ctrl-&gt;filterByLessQuantity(quantity); for(int i=0; i &lt; filtered.size(); i++){ int ID = filtered.getElement(i)-&gt;getID(); string name = filtered.getElement(i)-&gt;getName(); float concentration = filtered.getElement(i)-&gt;getConcentration(); int quantity = filtered.getElement(i)-&gt;getQuantity(); QString iDQString = QString::number(ID); QString nameQString = QString::fromStdString(name); QString concentrationQString = QString::number(concentration); QString quantityQString = QString::number(quantity); QString medicineAsString = iDQString+" - "+nameQString+" - "+concentrationQString+" - "+quantityQString; QListWidgetItem* item = new QListWidgetItem(medicineAsString, uiFilterMedicine.medFilterList); item-&gt;setData(Qt::UserRole,iDQString); } } </code></pre> <p>the filter function: The class: </p> <pre><code>class Filter{ public: virtual bool include(Medicine* m)=0; virtual ~Filter(){}; }; class LessThanQuantity: public Filter{ private: int quantity; public: LessThanQuantity(int q){ this-&gt;quantity=q; } bool include(Medicine* m){ return m-&gt;getQuantity()&lt;quantity; } }; </code></pre> <p>the filter functions from controller:</p> <pre><code>List&lt;Medicine*&gt; Controller::filterBy(Filter* filter){ List&lt;Medicine*&gt; rez = List&lt;Medicine*&gt;(); List&lt;Medicine*&gt; medList = repo-&gt;getAll(); Iterator&lt;Medicine*&gt; it = medList.getIterator(); for(it.first(); it.valid(); it.urmator()){ Medicine* m = it.element(); if(filter-&gt;include(m)){ rez.insert(rez.size(),m); } } return rez; } List&lt;Medicine*&gt; Controller::filterByLessQuantity(int quantity){ LessThanQuantity* f = new LessThanQuantity(quantity); return filterBy(f); } </code></pre> <p>Where am I doing wrong? If you need more information just tell me. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload