Skip to content

Commit 6bd3bfb

Browse files
author
Damir Porobic
committed
Add windows plugin load handling
1 parent de60242 commit 6bd3bfb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

example/main.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,24 @@ int main(int argc, char **argv)
6363
textLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
6464

6565
QDir pluginsDir(QLatin1String("../src/"));
66+
67+
#if defined(_WIN32)
68+
// Under Windows the 3rd Party Dlls are next to the plugin in the same directory
69+
// in order to find them we set the current directory to the plugin directory
70+
QDir::setCurrent(pluginsDir.path());
71+
#endif
72+
6673
const QStringList entries = pluginsDir.entryList(QDir::Files);
6774
for (const QString &fileName : entries) {
6875
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
6976
auto plugin = pluginLoader.instance();
70-
if (plugin) {
77+
if (plugin == nullptr) {
78+
if (!pluginLoader.metaData().isEmpty()) {
79+
qDebug() << "Error loading plugin" << fileName << pluginLoader.errorString();
80+
} else {
81+
qDebug() << "Checked" << fileName << "and it's not a plugin.";
82+
}
83+
} else {
7184
auto pluginOcr = qobject_cast<IPluginOcrOther*>(plugin);
7285
if (pluginOcr) {
7386
qDebug() << "Loaded plugin " << fileName << " with version " << pluginOcr->version();
@@ -77,7 +90,7 @@ int main(int argc, char **argv)
7790
qCritical() << "Unable to cast to interface";
7891
}
7992
pluginLoader.unload();
80-
}
93+
}
8194
}
8295

8396
mainWindow.show();

src/OcrWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ OcrWrapper::~OcrWrapper()
3131

3232
QString OcrWrapper::recognize(const QPixmap &pixmap) const
3333
{
34-
if (mTessApi->Init(nullptr, nullptr) == 0)
34+
if (mTessApi->Init(nullptr, "eng") == 0)
3535
{
3636
auto pix = makePixFromPixmap(pixmap);
3737
mTessApi->SetImage(pix);

0 commit comments

Comments
 (0)