Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QT Error message
exactMatch(self, str): first argument of unbound method must have type 'QRegExp'
I am getting this error after writing following line in my code : -
regexp = QRegExp.exactMatch(self, tag).
What is wrong with this?
@jsulm What should I use for exact string matching?
KroMignon last edited by
What should I use for exact string matching?
You have to create a
QRegExp()instance, then you can use
According to documentation https://doc.qt.io/qtforpython-5/PySide2/QtCore/QRegExp.html (I think you are using python):
rx = QRegExp("*.txt") rx.setPatternSyntax(QRegExp.Wildcard) rx.exactMatch("README.txt") # returns True rx.exactMatch("welcome.txt.bak") # returns False
@Prathamesh These are actually Python basics (has nothing to do with Qt):
regexp = QRegExp("YOUR_REGULAR_EXPRESSION_HERE") result = regexp.exactMatch(tag)
You should also use https://doc.qt.io/qt-5/qregularexpression.html instead of QRegExp.
@jsulm ok, i am new to both python and Qt as well.
artwaw last edited by
@Prathamesh I believe I cautioned you three or four times (in the thread you titled "Problem with/in QTreeview" or similar) that QRegExp is obsolete and much better effects you can have with QRegularExpression which you should use anyway...
@artwaw Yeah ,but my problem is how to set regexp? If I use QRegExp, I can do it by using self.filter_proxy_model.setFilterRegExp(regexp) <-- this way.
If I use QRegularExpression ,then I have to go for setRegularExpression() method if I understood it correctly. But this method is not available with our qt version. That is why I am looking for an alternatives.
This means that you are using Qt 4. Be aware that this version has reached end of life a long time ago so you should be careful what you implement with that.