I'm trying to write a simple C++ code using Qt to grab the path to a folder.
I got the code from this answer and tweaked it a bit to fit what I wanted. My problem is that it's flagging my 'this' declaration saying my class is incompatible with the 'QWidget *' parameter type.
#include <iostream>
#include <qt5/QtWidgets/qfiledialog.h>
using namespace std;
class TCC {
public:
string openFile();
};
string TCC::openFile()
{
QFileDialog::getOpenFileName(this, tr("Open Document"), QDir::currentPath(), tr("Document files (*.doc *.rtf);;All files (*.*)"), 0, QFileDialog::DontUseNativeDialog);
QString filename = QFileDialog::getOpenFileName(
this,
tr("Open Document"),
QDir::currentPath(),
tr("Document files (*.doc *.rtf);;All files (*.*)"));
if (!filename.isNull())
{
qDebug(filename.toUtf8());
}
return filename.toUtf8().constData();
}
int main()
{
TCC tcc;
cout << tcc.openFile();
}