分段错误(核心转储)Wt与Qt helloqt

时间:2015-08-22 07:44:17

标签: c++ qt wt

我之前写过,但细节没有解释。 我一步一步解释我的所作所为;

  1. Witty installation Guide Ubuntu

    我按照本页所述的顺序做了。

    sudo apt-get install gcc g ++ libboost-all-dev cmake make sudo apt-get install libssl-dev libfcgi-dev sudo apt-get install libpq-dev libmysqlclient-dev firebird-dev sudo apt-get install libpng12-dev libgraphicsmagick1-dev libhpdf-dev libpng12-dev libpango1.0-dev mesa-common-dev sudo apt-get install asciidoc libqt4-dev sudo apt-get install doxygen graphviz

    wget -c http://kent.dl.sourceforge.net/sourceforge/witty/wt-3.3.4.tar.gz tar xvxf wt-3.3.4.tar.gz

    cd wt-3.3.4 mkdir build cd build cmake .. 使 make -C examples

  2. 并测试helloqt.wt测试

    ./helloqt.wt --http-port 10000 --http-addr 0.0.0.0 --docroot .
    

    每件事都很好用

    然后我更改了某些Qt事件循环工作

    // Needed when using WQApplication with Qt eventloop = true
    #include <QApplication>
    
    Dictionary::Dictionary(const WEnvironment& env)
      : WQApplication(env , true )
    {
      /*
       * Note: do not create any Qt objects from here. Initialize your
       * application from within the virtual create() method.
       */
    }
    
    .
    .
    .
    int main(int argc, char **argv)
    {
      // Needed for Qt's eventloop threads to work
      QApplication app(argc, argv);
    
      return WRun(argc, argv, &createApplication);
    }
    

    仍然结果很好一切都好。 eventloops(信号/插槽工作)

    我用

    清理所有内容
    make clean
    

    将行添加到cmakefiles.txt QtNetwork

    .
    .
    .
    IF(ENABLE_QT4)
      FIND_PACKAGE(Qt4 REQUIRED QtCore QtGui QtNetwork)
    
      IF(QT_FOUND)
        INCLUDE(${QT_USE_FILE})
      ENDIF(QT_FOUND)
    ENDIF(ENABLE_QT4)
    .
    .
    .
    

    并添加到wtwithqt示例cmakelist.txt ${QT_QTNETWORK_LIBRARY}

      FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtNetwork )
    
      SET(QT_USE_QTNETWORK true)
    
      INCLUDE(${QT_USE_FILE})
    

    到下面

    IF(COMMAND cmake_policy)
      CMAKE_POLICY(SET CMP0003 NEW)
    ENDIF(COMMAND cmake_policy)
    
    SET(BUILD_WTWITHQT true)
    IF (NOT MULTI_THREADED_BUILD)
      SET(BUILD_WTWITHQT false)
    ENDIF (NOT MULTI_THREADED_BUILD)
    IF (NOT QT_FOUND)
      SET(BUILD_WTWITHQT false)
    ENDIF (NOT QT_FOUND)
    
    IF (NOT BUILD_WTWITHQT)
    
      MESSAGE(STATUS "** Not building wtwithqt example.")
      MESSAGE(STATUS "   wtwithqt example requires a Qt4 installation.")
    
    ELSE (NOT BUILD_WTWITHQT)
    
    
    
    
      MESSAGE("\n\n " + ${QT_QTCORE_LIBRARY} + " \n" + ${QT_QTGUI_LIBRARY} + "\n" +  ${QT_QTNETWORK_LIBRARY} + "\n" +    ${QT_LIBRARIES}  + "\n\n" )
    
      FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtNetwork )
    
      SET(QT_USE_QTNETWORK true)
    
      INCLUDE(${QT_USE_FILE})
    
      SUBDIRS(lib)
    
      ADD_DEFINITIONS(-DWT_NO_SLOT_MACROS)
    
      QT4_GENERATE_MOC(${CMAKE_CURRENT_SOURCE_DIR}/QtObject.h
                       ${CMAKE_CURRENT_BINARY_DIR}/moccedQtObject.C)
    
      WT_ADD_EXAMPLE(helloqt.wt
        hello.C
        QtObject.C
        ${CMAKE_CURRENT_BINARY_DIR}/moccedQtObject.C
      )
    
      TARGET_LINK_LIBRARIES(helloqt.wt
        wtwithqt
        ${QT_QTCORE_LIBRARY}
        ${QT_QTGUI_LIBRARY}
        ${QT_QTNETWORK_LIBRARY}
        ${QT_LIBRARIES}
      )
    
      #
      # If you have Wt installed somehwere, you should use the
      # installed Wt header files for your own Wt projects.
      # e.g. INCLUDE_DIRECTORIES(/usr/local/wt/include)
      # instead of the following:
      #
      INCLUDE_DIRECTORIES(
        ${WT_SOURCE_DIR}/src
        ${CMAKE_CURRENT_SOURCE_DIR}/lib
        ${QT_QTCORE_INCLUDE_DIR} 
        ${QT_QTNETWORK_INCLUDE_DIR} 
        ${QT_INCLUDE_DIR}
    
      )
    
    ENDIF (NOT BUILD_WTWITHQT)
    

    并添加到QTcpSocket以在下面运行 QtObject.h

    //这可能看起来像C代码,但它确实是 - - C ++ - -

    #ifndef QTOBJECT_H_
    #define QTOBJECT_H_
    
    #include <QThread>
    #include <QTcpSocket>
    
    class Dictionary;
    
    /*! \class QtObject
     *  \brief A simple Qt object with sample signal and slot.
     *
     * This simple object class demonstrates that the Qt signal/slot
     * mechanism may be used alonglisde Wt's signal/slot mechanism.
     */
    class QtObject : public QObject
    {
      Q_OBJECT;
    
    public:
      QtObject(Dictionary *wt_, QObject *parent = 0);
    
      void passGreet(const QString&);
    
      QTcpSocket* socket;
    
    signals:
      void greet(const QString&);
    
    public slots:
      void doGreet(const QString&);
      void Connected();
    
    private:
      Dictionary *wt_;
    };
    
    #endif // QTOBJECT_H_
    

    QtObject.C文件

     #include "HelloApplication.h"
    #include "QtObject.h"
    #include <QHostAddress>
    
    QtObject::QtObject(Dictionary *wt, QObject *parent)
      : QObject(parent),
        wt_(wt)
    { 
    
        socket = new QTcpSocket();
    
        QHostAddress adr;
    
        adr.setAddress("192.168.0.2");
    
        socket->connectToHost(adr,17776);
    
    
        QObject::connect(socket,SIGNAL(connected()),this,SLOT(Connected()));
    
    }
    
    void QtObject::passGreet(const QString& name)
    {
      emit greet(name);
    }
    
    void QtObject::doGreet(const QString& name)
    {
      wt_->doGreet(name);
    }
    
    
    void QtObject::Connected(){
    
        std::cout << "\n\nCONNNECTED\n\n";
        emit greet(QString("QString"));
    }
    

    从这时起

    cml@cml-All-Series:~/wt-3.3.4/build$ make clean
    cml@cml-All-Series:~/wt-3.3.4/build$ cmake ..
    cml@cml-All-Series:~/wt-3.3.4/build$ make -j8
    cml@cml-All-Series:~/wt-3.3.4/build$ make -C examples/wtwithqt
    
    
    cml@cml-All-Series:~/wt-3.3.4/build/examples/wtwithqt$ ./helloqt.wt charts.wt --http-port 10000 --http-addr 0.0.0.0 --docroot .
    [2015-Aug-22 10:34:04.692004] 3116 - [info] "WServer/wthttp: initializing built-in wthttpd"
    [2015-Aug-22 10:34:04.693292] 3116 - [info] "wthttp: started server: http://0.0.0.0:10000"
    

    点击浏览器0.0.0.0:10000 页面是传入和

    套接字发出Connected()信号和Connected()SLOT工作

    将屏幕打印到std::cout << "\n\nCONNNECTED\n\n";

    和申请

    坠毁。分段故障和核心转储

    我找不到有什么问题?

    我调试Qt Creator

    WWebWidget.C文件停在那里

        bool WWebWidget::canOptimizeUpdates()
        {
    ->      return WApplication::instance()->session()->renderer().preLearning();
        }
    

    Qt Creator调试器说 - &gt;

    The inferior stopped because it received a signal from the Operating System.
    
    Signal name : 
    SIGSEGV
    Signal meaning : 
    Segmentation fault
    

2 个答案:

答案 0 :(得分:0)

There talking about the solution

在我的代码中,我没有失败的故障段错误后删除了WText对象...

这对我来说不是解决方案,但我可以使用它

答案 1 :(得分:0)

Wt::WApplication* app = Wt::WApplication::instance();

app->enableUpdates(true);

Wt::WApplication::UpdateLock uilock(app);


if( uilock ){
   button->setText("Test"); //Here is Editable Widget
   app->trigerUpdate(); 
   app->enableUpdates(false);
}

对于大型工作,您可以锁定应用程序和

控制是否锁定改变任何东西 ServerPUSH.c