PDA

View Full Version : QTextDocument -no document error



poporacer
23rd March 2012, 02:02
I have a project that was originally developed in Creator 2.0.1 and when I try to run it on a new computer running Creator 2.4.1 it doesn’t work properly. I have a button that when pressed displays a manual. The code works fine on the other computer and when I copy the project to the new computer, clean the project, and rebuild the project, it displays a blank QTextDocument and in the appplication output window it shows “QTextBrowser: No document for UserManual.html” Here is the code I use:

void DlgHelpBrowser::showPage(const QString &page)
{
QString path= directoryOf("manual").absolutePath();
qDebug()<<"path"<<path;//when run, this shows the correct path
qDebug()<<"page"<<page;//and this shows the correct file
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;
}
I use the exact same code on both machines, a direct copy, and it works on one but not on the other. Any ideas?

ChrisW67
23rd March 2012, 03:04
Qt Creator is an IDE. Your choice of Qt Creator version has nothing to do with your code, the compiler, or the libraries it may be using.

If the problem is not in the code you posted then the problem is inside DlgHelpBrowser() or something it uses, which you don't show us. Show us code that is pertinent to the loading or display of the document or we will just be guessing.

poporacer
23rd March 2012, 03:30
I thought I included everything pertinent, sorry.
Here is the constructor:

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);
ui->textBrowser->setSearchPaths(QStringList() << path <<"/graphics");
ui->textBrowser->setSource(page);
ui->textBrowser->zoomIn(2);
}

And here is the code from the widget that calls the DlgHelpBrowser:

void MainWindow::on_actionUser_Manual_triggered()
{
DlgHelpBrowser::showPage("UserManual.html");
}
I think that is all the relevant code. That is what seems strange to me. The code is exactly the same, just using a different IDE and it doesn't work.

ChrisW67
23rd March 2012, 04:54
Plainly the QTextBrowser does not think the file exists in any of the search paths the text browser has been given.
Is the application location where you think it is?
Are the paths actually correct?
Does it work if you specify a file:// url (QUrl::fromLocalFile()) or absolute path rather than a bare file name?
Is the file name identical, including capitalisation?

Your IDE is irrelevant other than the environment and current working directory it sets when launching the program.
Are you using the same version of Qt on the two machines? Both 32- or 64-bit? Both Windows?


Incidentally, does "/graphics" exist? Which Windows drive would that be located on?

poporacer
23rd March 2012, 23:27
Is the application location where you think it is?
I have the application in a folder on my desktop.


Are the paths actually correct?I am pretty sure.
I even opened Windows explorer and compared the path in explorer to the one output in the debug statement.
Path from Windows Explorer- C:\Users\RTS\Desktop\MX Trainer Proxy version\manual
Path from dBug statement "C:/Users/RTS/Desktop/MX Trainer Proxy version/manual"


Does it work if you specify a file:// url (QUrl::fromLocalFile()) or absolute path rather than a bare file name?
I am not sure how to do this, I can't quite figure out the code to do this.


Is the file name identical, including capitalisation?
Yes it is


Your IDE is irrelevant other than the environment and current working directory it sets when launching the program.
Are you using the same version of Qt on the two machines? Both 32- or 64-bit? Both Windows?
The original machine is 32 bit the new machine is 64 bit, both Windows.


Incidentally, does "/graphics" exist? Which Windows drive would that be located on?
Yes it does, it exists as a subdirectory of "manual"

ChrisW67
24th March 2012, 07:28
In which directory does "UserManual.html" exist?

poporacer
24th March 2012, 13:39
It is in C:\Users\RTS\Desktop\MX Trainer Proxy version\manual. I think it is wierd that the exact same code would create such different results. My expectation is that the code in one IDE should create the same results in another IDE.

qt_surface
10th April 2012, 18:55
I'm having the exact same issue after upgrading from Qt 4.7 to 4.8. The upgrade coinsided with upgrading from Ubuntu Natty to Precise. I tried using an absolute path to no avail. I also tried converting the docs to be loaded through a qrc resource instead of pointing at a directory. My code looks similar t

HelpDialog::HelpDialog(QString helpFileName, QWidget *parent)
{
QString url;
url = "/usr/local/share/doc/nxtop/html/";

// Let the browser widget know where to search for help content
QStringList paths;
paths.append(url);
browser->setSearchPaths(paths);
browser->setSource(QUrl(helpFileName));
}

The construction of the widget:
...
helpDialog = new HelpDialog(helpFileName, helpDialogWindow);
helpDialogWindow->layout()->addWidget(helpDialog);
QRect size = helpDialog->geometry();
helpDialogWindow->setMinimumSize(size.width(), size.height());

// Pop up the dialog
helpDialogWindow->show();
}

poporacer
11th April 2012, 01:08
Use code tags around your code to make it easier to read.
Try
Your code is a little off:

QString url;
url = "/usr/local/share/doc/nxtop/html/";
// Let the browser widget know where to search for help content
QStringList paths;
paths.append(url);
browser->setSearchPaths(paths);
browser->setSource(QUrl(helpFileName));//change this to browser->setSource(QUrl::fromLocalFile(helpFileName));
}

I found that this is a reported bug (thanks to ChrisW67!!) And version 4.8 requires the fromLocalFile in order for it to work. hopefully this fixes your problem