PDA

View Full Version : QTextBroxser : home() problem



Nyphel
4th May 2007, 15:35
Hello !

I've a QTextBroxser that is linked to a HTML source.
The source is well displayed, but I've some matters when I want to use the links of my HTML source...

The links are well recognized by the widget, and the source is set to the new target when I clic a link. But when I want to use the home() function, my original source isn't displayed correctly... In reality, it isn't displayed at all :p
It's like if the source was wide, like if didn't contains anything...
So when I clic a button that call the home() function, my QTextBrowser is cleared().

That's funny, but I would prefer my source to be displayed :)

Have you got an idea, please ?

wysota
4th May 2007, 16:33
Did you set the original document using setSource()?

Nyphel
9th May 2007, 08:02
Yes :)

I used the QtDesigner tool in order to create my user interface, and there is a property to set the source. I've read the generated file content (.h) and the source is set with setSource(QUrl).

wysota
10th May 2007, 23:54
It seems to work quite fine for me... Check the attached ui file (adjust the source to match your Qt docs index.html). Also be sure to always change the active document using setSource().

Nyphel
24th May 2007, 09:10
Thanks Wysota, I didn't saw the answer before :)

This works well !

I had reimplemented the slots that could be set with the QtDesigner and I made an error.
I set the home_button to perform

my_text_box->home();
Certainly should I set :

my_text_box->setSource(home());

Nyphel
24th May 2007, 09:45
Hi,

I don't understand why but I can't make my browser to work.
When I execute my app, the browser is wide, clean, cleared... :D
When I open the .ui file, the browser looks well and the html content is displayed.
When I preview the .ui file, the browser is wide, clean, cleared... :(

The source is set in the .ui file, and never modified in my source code.

The only thing I've done since the last two weeks is to rebuild my Qt Open Source editon with the following configure.cache (under Win2000) :


-release
-static
-fast
-no-exceptions
-no-dsp
-no-vcproj
-no-rtti
-no-style-windowsxp

wysota
24th May 2007, 09:50
You're probably using a relative path for your source and Qt can't find it once the binary is moved to other place (like debug or release folders).

Nyphel
24th May 2007, 10:35
Yes this is a relative path : ../../help/help.html

This relative path is the same path for my .ui file and my .exe file.



my_project
|-- help
| |-- help.html
|
|-- gui
| |-- gui
| |-- help.ui
|
|-- my_app
| |-- { sources }
| |-- release
| |-- my_app.exe


But what I don't understand is that I don't move my application when I want to test it :confused:
Moreover I must set a relative path, cause this application will be deployed on ifferent OS (Linux, Win98, Win2000 and WinXP). Isn't it possible ?

wysota
24th May 2007, 11:27
You can embed the files you need into your executable and use the resource system to access them.

Nyphel
24th May 2007, 11:39
Mmmhhh... I think that this solution wouldn't be the best for me :o

I use a TextBrowser in order to be able to modify the help file without a complete rebuild of my application. So, if I embed it in the ressources file, wouldn't I lost this ability ? :confused:

wysota
24th May 2007, 12:05
You can do the embedding only when your application is being released and use real files when developing. Alternatively use file path relative to QApplication::applicationDirPath(), just make sure they are always correct. For example Windows compilers tend to move your application to different directories when compiling.

Nyphel
24th May 2007, 12:44
That's a great idea, thanks Wysota, but it doesn't resolve my problem :p

I think my installation is broken, cause it has worked very well before I rebuild my Qt Open Source edition with the static option.
Moreover, my compiler doesn't move the file while compiling (I've checked this point to be sure) and I'm pretty sure that if the QtDesigner editor can read the HTML file while editing the .ui, it should be able to read the content while doing the preview (with CTRL+D).

I don't really know what to do, but thanks for your help and tips, that helped me :)

wysota
24th May 2007, 12:45
Could you prepare a minimal compilable example that reproduces the problem?

Nyphel
24th May 2007, 13:37
I'm a .ui file similar to yours :)

The difference is that I'm under Win2000 and my path to the HTML file is [../../aide/accueil.html] and not [/usr/share/doc/qt4/doc/html/index.html].
("aide" stands for "help" in french)

I generate the header file with the command :
uic aide.ui -o aide.h

And I use an implementation class...



Here is my HTML :

<html>
<head>
</head>

<body>
huhuhuh hin hin hin !
<br /><br />
<a href="suite.html">a link</a>
</body>

</html>
(I made some links to test the forward/backward/home functionnalities)



Here is my implementation class :


#ifndef Aide_impl_h
#define Aide_impl_h

#include "../gui/gui/ui_aide.h"

#include <QObject>
#include <QDialog>
#include <QtGui>
#include <QUrl>

class Aide_impl : public QDialog, public Ui::dialog_Aide
{
Q_OBJECT

public:
Aide_impl(QWidget *parent = 0);

protected:

private slots:

private:
};

#endif // Aide_impl_h



Aide_impl::Aide_impl(QWidget *parent) : QDialog(parent)
{
setupUi(this);
}



And I use it in my application :


Aide_impl my_help_window = new Aide_impl(this);
my_help_window->show();

wysota
24th May 2007, 14:07
So where do you set the path?

Nyphel
24th May 2007, 14:37
Here I've removed the QApplication::applicationDirPath(), it is set in the .ui file for the moment.

Otherwise I've tried it in the constructor of my implementation class and in my application, like this :


QString acces_app = QApplication::applicationDirPath();
acces_app.append("../../aide/accueil.html");
QUrl url_source(acces_app);
my_help_window->TB_message->setSource(url_source);


But that didn't change anything :(

wysota
24th May 2007, 16:57
Could you first try with QFile::exists() if the path is correct? Displaying the path in console just to make sure it is correct might be a good idea as well... I think you're at least missing a slash here...

Nyphel
25th May 2007, 08:21
Yes, the path semmes to be correct :).

The path accepted are :
../../aide/accueil.html
/../../aide/accueil.html
acces_app.append("/../../aide/accueil.html");

You're true, a slash was missing in acces_app :).
I've test with it, that doesn't work anyway :(

wysota
25th May 2007, 08:51
So what exactly happens if you call setSource() with that url?

Nyphel
25th May 2007, 11:12
Nothing : the QTextBrowser is wide, no HTML text is displayed.
Sometimes, I've the texte... But if I modify the HTML file content (not the name), and rebuild my application, the QTextBrowser is cleared another time... :(

A funny thing is that if I do a simple

setText("lol <br> <b>huhu</b>");
instead of the setSource(...); the HTML text is well displayed.

Nyphel
25th May 2007, 12:30
Yes !

I solved the problem like this :


QStringList chemins;
chemins << "../../aide/";

QString acces_app = "accueil.html";
QUrl url_source(acces_app);

my_help_window->TB_message->setSearchPaths (chemins);
my_help_window->TB_message->setSource(url_source);




source : QUrl

This property holds the name of the displayed document.
This is a an invalid url if no document is displayed or if the source is unknown.
When setting this property QTextBrowser tries to find a document with the specified name in the paths of the searchPaths property and directory of the current source, unless the value is an absolute file path. It also checks for optional anchors and scrolls the document accordingly

If the first tag in the document is <qt type=detail>, the document is displayed as a popup rather than as new document in the browser window itself. Otherwise, the document is displayed normally in the text browser with the text set to the contents of the named document with setHtml().

Access functions:
QUrl source () const
virtual void setSource ( const QUrl & name )


At the beginning, in my aide.ui file, I had set the setSource property.
I let the setSearchPaths wide, with no path specified (I understood that this property should facilitate access to linked files or displayed images...).
So, it should have displayed my HTML file when calling the implementation class object in my application, without setting other setSource property... But the document was cleared, the content of the HTML source file wasn't displayed. Perhaps it's a bug, perhaps I am the bug (certainly...:D ), but I'll never know.

After that, I tried to set the HTML source directly from my application.
My error was to set (another time...) the setSource property in the application, cause the relative path was specified from the searchPath definied originally in my aide.ui file : none !

So the final solution is :
- not to set the setSource property in my aide.ui file
- set the setSearchPaths list property in my aide.ui file ("../../aide/")
- set the setSource property in my application ("accueil.html")



One more time, let me thank you a lot for your help and participation :)




PS : Arrrghhh....
Now my links (<a href...>) are no more resolved... :(
Nothing happens when I click a link, the source stay the same, the content displayed isn't changed. If I open it with Firefox, links a well resolved.

If I want them to work, I must specify the setSource property in my aide.ui file.
So I specify the setSource and the setSearchPaths list properties in my aide.ui file.