1

I want to use QValidator and its subclasses (QRegExpValidator, QIntValidator) in QCoreApplication, but get the following error: "QValidator: No such file or directory" If I add in .pro file the following line: "QT += gui" - all works fine, but that is not a solution for me.

Is there any technique to use QValidator in QCoreApplications?

j0k
  • 22,600
  • 28
  • 79
  • 90
  • write why you need validators in qt core application. QValidator is design to work with QLineEdit. – Marek R Aug 19 '13 at 08:32
  • I decided to use QValidator to validate program arguments. Smth like this: if (validator.validate(QString(argv[1]),0) != QValidator::Acceptable ... For examaple, if first parameter is an IP address and I want to check it correctness – Sergey Pakhomov Aug 19 '13 at 10:41
  • so QValidator is to big machine for you (you don't need intermediate state or cursor information). `QRegExp`, `QString::toInt`, `QString::toDouble` should do the job (if you need localized validation then respective functions of `QLocale` should be ok). – Marek R Aug 19 '13 at 10:58
  • Thank you! Henceforth I will read qt docs much closer ;) QRegExp & QString done all the job! – Sergey Pakhomov Aug 20 '13 at 08:46

1 Answers1

2

No, this is not possible. QValidator is part of the gui lib. I suppose the Qt devs thought that QValidator makes only sense with Qt's text input classes. I checked again, above statement is still true. However, I looked into the code, QValidator does not depend on any gui stuff. On first glance it seems to be rather stand-alone. So you might be able to copy qvalidator.cpp and qvalidator.h from the Qt sources into your sources, do a reasonable amount of adjusting, and integrate this into your code. It might be possible, I don't say it will be easy.

Greenflow
  • 3,935
  • 2
  • 17
  • 28