Results 1 to 9 of 9

Thread: How to show MS Word int QWidget ?

  1. #1
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    3

    Default How to show MS Word int QWidget ?

    Hello, I want to show MS Word in QWidget, I 've tried like this:

    In a QWidget's constructor:

    Qt Code:
    1. QString qsFileName( "D:/Test/Test.doc" );
    2.  
    3. QHBoxLayout *playout = new QHBoxLayout( this );
    4. setLayout( playout );
    5.  
    6. QAxWidget *pAxWidget = new QAxWidget( this );
    7.  
    8. playout->addWidget( pAxWidget );
    9. playout->setMargin( 0 );
    10.  
    11. pAxWidget ->setControl( qsFileName );
    To copy to clipboard, switch view to plain text mode 

    Use this method, I can show it in a QWidget, but these menubars and commandbars are hidden.

    So I tried to make them visible like this:

    Qt Code:
    1. QAxObject *pStandard = pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Standard" );
    2. pStandard->dynamicCall( "Enabled", true );
    3. pStandard->dynamicCall( "Visible", true );
    4. QAxObject *pFormatting = pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Formatting" );
    5. pFormatting->dynamicCall( "Enabled", true );
    6. pFormatting->dynamicCall( "Visible", true );
    To copy to clipboard, switch view to plain text mode 

    but I still cannot see any commandBar.

    Can you help me? Thanks.
    Last edited by luoyes; 6th January 2011 at 05:44.

  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: How to show MS Word int QWidget ?

    Are you sure those objects have properties Enabled and Visible?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    luoyes (6th January 2011)

  4. #3
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    3

    Default Re: How to show MS Word int QWidget ?

    Thanks for you attention.
    Yes, I'm sure, I found it in the MSDN.
    I think the problem is there is no room to show these commandbars.There must be some pannel or something else should be turned on, or use QAxWidget::setControl() with a file name is not a good way.

  5. #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: How to show MS Word int QWidget ?

    What does generateDocumentation() for each of the subobjects return?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    luoyes (7th January 2011)

  7. #5
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    3

    Default Re: How to show MS Word int QWidget ?

    Returns nothing.

    Here is all the code.

    Qt Code:
    1. QString qsFileName( "D:/Test/Test.doc" );
    2.  
    3. QHBoxLayout *playout = new QHBoxLayout( this );
    4. setLayout( playout );
    5.  
    6. m_pAxWidget = new QAxWidget( this );
    7.  
    8. playout->addWidget( m_pAxWidget );
    9. playout->setMargin( 0 );
    10.  
    11. m_pAxWidget->setControl( qsFileName );
    12.  
    13. QAxObject *pStandard = m_pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Standard" );
    14. pStandard->dynamicCall( "Enabled", true );
    15. pStandard->dynamicCall( "Visible", true );
    16. QAxObject *pFormatting = m_pAxWidget->querySubObject( "CommandBars( const QVariant & )", "Formatting" );
    17. pFormatting->dynamicCall( "Enabled", true );
    18. pFormatting->dynamicCall( "Visible", true );
    19.  
    20. qDebug() << pStandard->generateDocumentation();
    21. qDebug() << pFormatting->generateDocumentation();
    To copy to clipboard, switch view to plain text mode 

  8. #6
    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: How to show MS Word int QWidget ?

    Ok, also check pStandard->isNull() and pFormatting->isNull(). I have a feeling your sub object calls are invalid. Also try dumping QAxBase::propertyBag() for those subobjects if they are not null. You can dump the properties for your m_pAxWidget object too.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #7
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    3

    Default Re: How to show MS Word in QWidget ?

    Quote Originally Posted by wysota View Post
    Ok, also check pStandard->isNull() and pFormatting->isNull(). I have a feeling your sub object calls are invalid. Also try dumping QAxBase::propertyBag() for those subobjects if they are not null. You can dump the properties for your m_pAxWidget object too.
    Thanks for your patience

    I checked pStandard->isNull() and pFormatting->isNull(). They returned false.

    And the properties are right. Both Visible and Enabled are true.

    So I think the problem is there is no space to show them. I tried to get CommandBar's parent and make it visible, but that made the word application visible out of my widget.

    So maybe it is not very easy to show Word in QWidget with commandBars. It needs much more work to do.

    Thanks again.

  10. #8
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    110
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to show MS Word in QWidget ?

    Did you find the solution already? I'm eagerously looking for the solution all the time these days. Could you please share your solution at your convenience ?


    Cheers
    Pei
    Welcome to Vision Open
    http://www.visionopen.com

  11. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to show MS Word in QWidget ?

    Did you find the solution already?
    I think the original poster's problem is that he was trying to create an embedded MS Word ActiveX object simply by trying to open a Word document. This is completely dependent on the ".doc" extension being assigned to Word documents in MS Windows. On my PC, I use Apache OpenOffice, and when I open a ".doc" file, it opens in OpenOffice, not MS Word.

    In order to get this to work correctly, you need to use the GUID for the MS Word COM object in the setControl() call, not the name of the file you want to open. Once you have the MS Word COM object instantiated, you can use it to open the document and display it.

    There are plenty of examples on how to do this. I would start with this article It uses MS Excel, but MS Word is basically the same thing. The COM object model for MS Word can be found here.

Similar Threads

  1. Replies: 10
    Last Post: 11th June 2012, 09:16
  2. setFocus after hide and show qwidget
    By alexandernst in forum Newbie
    Replies: 0
    Last Post: 14th April 2010, 17:25
  3. Replies: 3
    Last Post: 27th February 2008, 08:01
  4. QWidget::exec() and QWidget::show()
    By MarkoSan in forum Qt Programming
    Replies: 6
    Last Post: 18th October 2007, 21:39
  5. QWidget::show () segmentation fault
    By Umar Said in forum Qt Programming
    Replies: 6
    Last Post: 27th September 2007, 05:50

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.