Results 1 to 9 of 9

Thread: QTextDocument -no document error

  1. #1
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QTextDocument -no document error

    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:
    Qt Code:
    1. void DlgHelpBrowser::showPage(const QString &page)
    2. {
    3. QString path= directoryOf("manual").absolutePath();
    4. qDebug()<<"path"<<path;//when run, this shows the correct path
    5. qDebug()<<"page"<<page;//and this shows the correct file
    6. DlgHelpBrowser *browser = new DlgHelpBrowser (path, page);
    7. browser->resize(1000, 800);
    8. browser->show();
    9. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QDir DlgHelpBrowser::directoryOf(const QString &subdir)
    2. {
    3. QDir dir(QApplication::applicationDirPath());
    4. if (dir.dirName().toLower()== "debug" || dir.dirName().toLower()=="release")
    5. dir.cdUp();
    6. dir.cd(subdir);
    7. return dir;
    8. }
    To copy to clipboard, switch view to plain text mode 
    I use the exact same code on both machines, a direct copy, and it works on one but not on the other. Any ideas?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,594
    Thanks
    13
    Thanked 1,588 Times in 1,517 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTextDocument -no document error

    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.

  3. #3
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextDocument -no document error

    I thought I included everything pertinent, sorry.
    Here is the constructor:
    Qt Code:
    1. DlgHelpBrowser::DlgHelpBrowser(const QString &path, const QString &page,
    2. QWidget *parent) :
    3. QDialog(parent),
    4. ui(new Ui::DlgHelpBrowser)
    5. {
    6. ui->setupUi(this);
    7. setAttribute(Qt::WA_DeleteOnClose);
    8. setAttribute(Qt::WA_GroupLeader);
    9. ui->textBrowser->setSearchPaths(QStringList() << path <<"/graphics");
    10. ui->textBrowser->setSource(page);
    11. ui->textBrowser->zoomIn(2);
    12. }
    To copy to clipboard, switch view to plain text mode 

    And here is the code from the widget that calls the DlgHelpBrowser:
    Qt Code:
    1. void MainWindow::on_actionUser_Manual_triggered()
    2. {
    3. DlgHelpBrowser::showPage("UserManual.html");
    4. }
    To copy to clipboard, switch view to plain text mode 
    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.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,594
    Thanks
    13
    Thanked 1,588 Times in 1,517 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTextDocument -no document error

    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?

  5. #5
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextDocument -no document error

    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"

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,594
    Thanks
    13
    Thanked 1,588 Times in 1,517 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTextDocument -no document error

    In which directory does "UserManual.html" exist?

  7. #7
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextDocument -no document error

    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.

  8. #8
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextDocument -no document error

    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();
    }

  9. #9
    Join Date
    Aug 2010
    Posts
    107
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextDocument -no document error

    Use code tags around your code to make it easier to read.
    Try
    Your code is a little off:
    Qt Code:
    1. QString url;
    2. url = "/usr/local/share/doc/nxtop/html/";
    3. // Let the browser widget know where to search for help content
    4. paths.append(url);
    5. browser->setSearchPaths(paths);
    6. browser->setSource(QUrl(helpFileName));//change this to browser->setSource(QUrl::fromLocalFile(helpFileName));
    7. }
    To copy to clipboard, switch view to plain text mode 
    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

Similar Threads

  1. document collaboration
    By shaan in forum Qt-based Software
    Replies: 1
    Last Post: 15th November 2010, 05:31
  2. Append to a XML Document
    By Goldmmbr in forum Qt Programming
    Replies: 0
    Last Post: 16th November 2009, 15:03
  3. Help document
    By weixj2003ld in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2009, 12:04
  4. open a document
    By peace_comp in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2008, 07:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.