Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: QTextBroxser : home() problem

  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default QTextBroxser : home() problem

    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
    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    Did you set the original document using setSource()?

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    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).

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    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().
    Attached Files Attached Files

  5. The following user says thank you to wysota for this useful post:

    Nyphel (24th May 2007)

  6. #5
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    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
    Qt Code:
    1. my_text_box->home();
    To copy to clipboard, switch view to plain text mode 
    Certainly should I set :
    Qt Code:
    1. my_text_box->setSource(home());
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    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...
    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) :
    Qt Code:
    1. -release
    2. -static
    3. -fast
    4. -no-exceptions
    5. -no-dsp
    6. -no-vcproj
    7. -no-rtti
    8. -no-style-windowsxp
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    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).

  9. #8
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    Yes this is a relative path : ../../help/help.html

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

    Qt Code:
    1. my_project
    2. |-- help
    3. | |-- help.html
    4. |
    5. |-- gui
    6. | |-- gui
    7. | |-- help.ui
    8. |
    9. |-- my_app
    10. | |-- { sources }
    11. | |-- release
    12. | |-- my_app.exe
    To copy to clipboard, switch view to plain text mode 

    But what I don't understand is that I don't move my application when I want to test it
    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 ?

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    You can embed the files you need into your executable and use the resource system to access them.

  11. #10
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    Mmmhhh... I think that this solution wouldn't be the best for me

    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 ?
    Last edited by Nyphel; 24th May 2007 at 11:47.

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    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.

  13. The following user says thank you to wysota for this useful post:

    Nyphel (25th May 2007)

  14. #12
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    That's a great idea, thanks Wysota, but it doesn't resolve my problem

    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

  15. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    Could you prepare a minimal compilable example that reproduces the problem?

  16. #14
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    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 :
    Qt Code:
    1. <html>
    2. <head>
    3. </head>
    4.  
    5. <body>
    6. huhuhuh hin hin hin !
    7. <br /><br />
    8. <a href="suite.html">a link</a>
    9. </body>
    10.  
    11. </html>
    To copy to clipboard, switch view to plain text mode 
    (I made some links to test the forward/backward/home functionnalities)



    Here is my implementation class :
    Qt Code:
    1. #ifndef Aide_impl_h
    2. #define Aide_impl_h
    3.  
    4. #include "../gui/gui/ui_aide.h"
    5.  
    6. #include <QObject>
    7. #include <QDialog>
    8. #include <QtGui>
    9. #include <QUrl>
    10.  
    11. class Aide_impl : public QDialog, public Ui::dialog_Aide
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. Aide_impl(QWidget *parent = 0);
    17.  
    18. protected:
    19.  
    20. private slots:
    21.  
    22. private:
    23. };
    24.  
    25. #endif // Aide_impl_h
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Aide_impl::Aide_impl(QWidget *parent) : QDialog(parent)
    2. {
    3. setupUi(this);
    4. }
    To copy to clipboard, switch view to plain text mode 



    And I use it in my application :
    Qt Code:
    1. Aide_impl my_help_window = new Aide_impl(this);
    2. my_help_window->show();
    To copy to clipboard, switch view to plain text mode 

  17. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    So where do you set the path?

  18. #16
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    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 :
    Qt Code:
    1. QString acces_app = QApplication::applicationDirPath();
    2. acces_app.append("../../aide/accueil.html");
    3. QUrl url_source(acces_app);
    4. my_help_window->TB_message->setSource(url_source);
    To copy to clipboard, switch view to plain text mode 

    But that didn't change anything
    Last edited by Nyphel; 24th May 2007 at 14:53.

  19. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    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...

  20. The following user says thank you to wysota for this useful post:

    Nyphel (25th May 2007)

  21. #18
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    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

  22. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextBroxser : home() problem

    So what exactly happens if you call setSource() with that url?

  23. #20
    Join Date
    Feb 2007
    Posts
    158
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextBroxser : home() problem

    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
    Qt Code:
    1. setText("lol <br> <b>huhu</b>");
    To copy to clipboard, switch view to plain text mode 
    instead of the setSource(...); the HTML text is well displayed.
    Last edited by Nyphel; 25th May 2007 at 11:56.

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.