[Ace-users] QtReactor usage

Derek derek_baikie at hotmail.com
Sun Mar 9 13:34:13 CDT 2008


hi, I have been trying to build a sample program that uses QT4.3.0 and
ACE.
I have a QTReactor, but am unsure of usage.

The following example program, extends one of the ACE timer tests,
setting the value of a pushbutton.
When I end the main code by calling ACE_Reactor::instance()-
>run_event_loop(), I get the timer events (but not the QT events), and
when I call a.exec I get the QT events, but not the ACE events.

Would anyone be able to describe how to interleave these event
handlers?

MY code (compiles) is as follows:

#include "QApplication.h"
#include "QPushButton.h"

#include "ace/OS_main.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_sys_time.h"

#include "ace/Task.h"
#include "ace/QtReactor/QtReactor.h"

#include <stdio.h>
#include <iostream>

class CB : public ACE_Event_Handler
{
public:
  CB (int id, QApplication *app) : id_(id)
  {
	  hello = new QPushButton("Hello");
	  hello->resize(100, 30);
	  QObject::connect(hello, SIGNAL(clicked()), app, SLOT(quit()));
	  hello->show();
  }

  virtual int handle_timeout (const ACE_Time_Value &,
                              const void *arg)
  {
    if (hello->text() == "Hello")
		hello->setText("Goodbye");
	else
		hello->setText("Hello");

	hello->repaint();
    return 0;
  }



private:
  int id_;
  QPushButton *hello;
};


int main(int argc, char **argv)
{
  // Schedule a timer to go off 2 seconds later and then
  // ater every 4 seconds.
  QApplication a( argc, argv );
  ACE_QtReactor qt_reactor( &a );
  ACE_Reactor r( &qt_reactor);
  ACE_Reactor::instance( &r );

  CB cb (1, &a);
  int arg = -1;
  ACE_Time_Value initial (1);
  ACE_Time_Value repeat (3);
  ACE_Reactor::instance ()->schedule_timer(&cb, &arg, initial,
repeat);

  //a.exec();  //qt events not working
  ACE_Reactor::instance ()->run_event_loop(); //click event not
working
  return (0);
}


More information about the Ace-users mailing list