QAxObject problem



  • Good day every one.

    I have some trouble with QAxObject's initialization. The programm must read a .doc file, which why i use QAxObject. But i don't understand whats goin on, when i try simply open or add a new one. I look up some code examples, but they give me SEGMENTATION FAULT. Here it is:

    @QAxObject* WordApplication=new QAxObject("Word.Application"); // Создаю интерфейс к MSWord
    QAxObject* WordDocuments = WordApplication->querySubObject( "Documents()" );
    QAxObject* NewDocument = WordDocuments->querySubObject("Open(const QString&, bool)",FileNameAndPath, true);@

    And that's all for now. qDebug tell me some thing like that:
    "QAxBase::setControl: requested control Word.Application could not be instantiated.
    QAxBase::dynamicCallHelper: Object is not initialized, or initialization failed."
    This messages shows before SIGSEGV signal was received. I,am just stuck.

    Many thank in advance for any attention to this problem.



  • SIGSEGV error is when you application tries to access RAM outside it's giver scope. OS force stops it.
    Can you paste code where qDebug shows error?



  • Hi, its my code, I tested by Win7 + Word 2007 and works good )

    @
    QAxObject *word;
    QAxObject *doc;
    word = new QAxObject("Word.Application", this);
    word->setProperty("DisplayAlerts", false);
    word->setProperty("Visible", true);
    doc = word->querySubObject("Documents");
    doc->dynamicCall("Open(QVariant)", "d:\a15.doc");
    @



  • [quote author="Jake007" date="1332077759"]SIGSEGV error is when you application tries to access RAM outside it's giver scope. OS force stops it.
    Can you paste code where qDebug shows error?[/quote]

    All ready did it. qDebug shows error on
    @
    QAxObject* WordApplication=new QAxObject("Word.Application"); // Создаю интерфейс к MSWord
    QAxObject* WordDocuments = WordApplication->querySubObject( "Documents()" );
    @

    SIGSEGV shows up on this row:
    @QAxObject* NewDocument = WordDocuments->querySubObject("Open(const QString&, bool)",FileNameAndPath, true);@

    [quote author="Skyrim" date="1332082018"]Hi, its my code, I tested by Win7 + Word 2007 and works good )

    @
    QAxObject *word;
    QAxObject *doc;
    word = new QAxObject("Word.Application", this);
    word->setProperty("DisplayAlerts", false);
    word->setProperty("Visible", true);
    doc = word->querySubObject("Documents");
    doc->dynamicCall("Open(QVariant)", "d:\a15.doc");
    @
    [/quote]

    Is really need to indicate path to file throw "\"? Can i also ask you some info about querySubObject? I tried to use generateDocumentation, but it failed. Have you example working code, or resource about this theme?



  • So you got it or not, and an example of what you are looking for.
    Here's an example creating a new document.
    @
    QAxObject *word;
    QAxObject *doc;
    word = new QAxObject("Word.Application", this);
    word->setProperty("DisplayAlerts", false);
    word->setProperty("Visible", true);
    doc = word->querySubObject("Documents");
    doc->dynamicCall("Add()");
    // doc = word->querySubObject("Documents")->dynamicCall("Add()"); // its working too
    @

    For help "this tread ":http://qt-project.org/forums/viewthread/1871/ about Excel



  • Same error even on the code od Skyrim. Behavior of program are similar:
    @“QAxBase::setControl: requested control Word.Application could not be instantiated.
    QAxBase::dynamicCallHelper: Object is not initialized, or initialization failed.”@

    on steps:

    @@word = new QAxObject("Word.Application", this);@
    and
    @doc = word->querySubObject("Documents");@

    accordingly.

    My .pro file just in case:
    @
    QT += core

    QT -= gui

    TARGET = compare
    CONFIG += console
    CONFIG -= app_bundle qaxcontainer

    TEMPLATE = app

    LIBS += -lqaxcontainer

    SOURCES += main.cpp
    compare.cpp

    HEADERS +=
    compare.h

    OTHER_FILES +=@



  • ok in .pro file must be line

    @CONFIG += qaxcontainer@

    in .h file

    @
    #include <ActiveQt/qaxbase.h>
    #include <ActiveQt/qaxobject.h>
    @



  • Done, but no effect.



  • my .pro
    @
    QT += core gui
    TARGET = andWord
    TEMPLATE = app
    SOURCES += main.cpp
    mainwindow.cpp
    HEADERS += mainwindow.h
    FORMS += mainwindow.ui
    CONFIG += qaxcontainer
    @
    my .h
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <ActiveQt/qaxbase.h>
    #include <ActiveQt/qaxobject.h>
    namespace Ui {
    class MainWindow;
    }
    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    QAxObject *word;
    QAxObject *doc;
    private:
    Ui::MainWindow *ui;
    public slots:
    void runWord();
    void quitWord();
    void setWordVisible(bool vis);
    void addDoc();
    };
    #endif // MAINWINDOW_H
    @

    and .cpp
    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    connect(ui->pushButton_run, SIGNAL(clicked()), this, SLOT(runWord()));
    connect(ui->pushButton_quit, SIGNAL(clicked()), this, SLOT(quitWord()));
    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(addDoc()));
    connect(ui->checkBox_visible, SIGNAL(clicked(bool)), this, SLOT(setWordVisible(bool)));
    }
    MainWindow::~MainWindow()
    {
    delete ui;
    }
    void MainWindow::runWord(){
    word = new QAxObject("Word.Application", this);
    word->setProperty("DisplayAlerts", false);
    doc = word->querySubObject("Documents");
    //doc->dynamicCall("Open(QVariant)", "d:\a15.doc");
    }
    void MainWindow::quitWord(){
    doc->dynamicCall("Close()");
    word->dynamicCall("Quit()");
    }
    void MainWindow::setWordVisible(bool vis){
    word->setProperty("Visible", vis);
    }
    void MainWindow::addDoc(){
    doc->dynamicCall("Add()");
    }
    @



  • Qt show error on this row:
    @word = new QAxObject("Word.Application", this);
    @

    Error message is:
    @..\compare\compare.cpp:69: error: no matching function for call to 'QAxObject::QAxObject(const char [17], compare* const)'@

    Maybe thing is in fact, what i have console application with added C++ class. How declare this method correctly in this case?



  • Ok... after pasting code in solution with form and interface it's start work! Great! Now, there is a one problem, what still remains: i don't khown how to READ test from word file. I have founded a lot of examples inserting text in file, but no one, not ANY one don't wish to show me how QAxObject can READ text from file. If you can show it, i'll be very grateful.



  • Ok, i have some progress - finally a i can read .doc files. That's great! But, unfortunately, there was another problem.

    I have read about "linebreak" in .doc files, instead "\n". Linebreak denotes "\v". In beginning it works, and ,i started think, what problem was solved, but suddenly, linebreak stopped denotes. In QString it was just empty symbol (""), my condition on detecting empty string was ignored:

    @
    words = docA->querySubObject("Words");
    QString textResult; //будущий результат
    int countWord = words->dynamicCall("Count()").toInt(); //кол-во слов в тексте

    QString testString;
    int asciiCode;
    //на самом деле он обманывает, считает зараза с пробелами :(
    for (int a = 1; a <= countWord; a++)
    {
    if(testString.count()==1)
    {
    asciiCode=testString.toLocal8Bit().toInt();
    textResult.append("\v");
    }
    else if(testString.isEmpty())
    {-------//------------}
    else if(testString.isNull())
    {-------//------------}
    else if(testString=="")
    {-------//------------}
    else if(testString=="\v")
    {-------//------------}
    else
    textResult.append(words->querySubObject("Item(int)", a)->dynamicCall("Text()").toString());
    testString.clear();
    }
    @

    What the most intersting, that is ascii code of this empty symbol. It's =0. To tell the truth, i use integer number to detect the code, so I could be wrong.

    Please, help somebody with this!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.