QTextBrowser setSearchPaths not working correctly
-
I am trying to set up a user manual and followed the method in C++ Gui Programming with Qt. It worked exactly as planned on Qt Creator version 2.0.1 using Qt 4.7. I then transferred the code to Creator Version 2.4.1 using Qt 4.7.4 and it didn't work. At first the browser window would not load anything. My file structure has the application and then a subfolder for the manual, then a subfolder in manual for the graphic files. So I have root/manual/graphics. I modified the code and now the manual shows, but it does not show the pictures unless I move the graphics subfolder to the root directory. Here is what I have:
Original code:
@DlgHelpBrowser::DlgHelpBrowser(const QString &path, const QString &page,
QWidget *parent) :
QDialog(parent),
ui(new Ui::DlgHelpBrowser)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_GroupLeader);connect (ui->btnHome, SIGNAL(clicked()), ui->textBrowser, SLOT (home())); connect (ui->btnBack, SIGNAL(clicked()), ui->textBrowser, SLOT (backward())); connect (ui->btnClose, SIGNAL(clicked()), this, SLOT (close())); ui->textBrowser->setSearchPaths(QStringList() << path <<"/graphics"); ui->textBrowser->setSource(page);
}@
@void DlgHelpBrowser::showPage(const QString &page)
{
QString path= directoryOf("manual").absolutePath();
DlgHelpBrowser *browser = new DlgHelpBrowser ( path, page);
browser->resize(1000, 800);
browser->show();
}@
@QDir DlgHelpBrowser::directoryOf(const QString &subdir)
{
QDir dir(QApplication::applicationDirPath());
if (dir.dirName().toLower()== "debug" || dir.dirName().toLower()=="release")
dir.cdUp();dir.cd(subdir); return dir;
}@
The above code works correctly in Creator 2.0.1 with Qt 4.7 but with Qt 4.7.4 the QTextBrowser is blank and an error message "QTextBrowser: No document for UserManual.html"
To get UserManual to show I had to change the code to:
@DlgHelpBrowser::DlgHelpBrowser(const QString &path, const QString &page,
QWidget *parent) :
QDialog(parent),
ui(new Ui::DlgHelpBrowser)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_GroupLeader);connect (ui->btnHome, SIGNAL(clicked()), ui->textBrowser, SLOT (home())); connect (ui->btnBack, SIGNAL(clicked()), ui->textBrowser, SLOT (backward())); connect (ui->btnClose, SIGNAL(clicked()), this, SLOT (close())); QUrl loadPage =QUrl::fromLocalFile(page); //New line added ui->textBrowser->setSearchPaths(QStringList() << path <<"/graphics"); // I even tried path + "/graphics" ui->textBrowser->setSource(loadPage);//Variable name changed
}@
But with this code, the images in the graphics subfolder do not show up. If I move the graphics folder to the root of the application, the images show... Which is wierd, because the html code references the images as src="graphics/mainMenu.jpg". Any ideas why this is working strangely? And how do I get it to work properly? I really don't want to have 2 copies of the graphics subfolder.