friend void adl_postconstruct(const boost::shared_ptr<T> &view_sp, HexView *view, Document& doc) { view->m_document = &doc; { typedef Document::signal_t::slot_type slot_type; slot_type myslot(&HexView::refresh, view); doc.connect(myslot.track(view_sp)); } }
MyWidget::MyWidget() { connect( this, SIGNAL( mysignal() ), this, SLOT(myslot()) ); // NOTE: DO NOT include the name of the paramter when using signals/slots with parameters. // It will compile, but give you "undefined signal" errors at runtime. // I.e. use // connect( this, SIGNAL( mysignal(QVector<double>) ), this, SLOT(myslot(QVector<double>)) ); // instead of // connect( this, SIGNAL( mysignal(QVector<double> coord) ), this, SLOT(myslot(QVector<double> coord)) ); }
void test_extended_slot() { { typedef boost::signals2::signal1<ResultType, int> signal_type; typedef typename signal_type::extended_slot_type slot_type; signal_type sig; // attempting to work around msvc 7.1 bug by explicitly assigning to a function pointer ResultType (*fp)(const boost::signals2::connection &conn, int) = &disconnecting_slot<ResultType>; slot_type myslot(fp); sig.connect_extended(myslot); BOOST_CHECK(sig.num_slots() == 1); sig(0); BOOST_CHECK(sig.num_slots() == 0); } { // test 0 arg signal typedef boost::signals2::signal0<ResultType> signal_type; typedef typename signal_type::extended_slot_type slot_type; signal_type sig; // attempting to work around msvc 7.1 bug by explicitly assigning to a function pointer ResultType (*fp)(const boost::signals2::connection &conn, int) = &disconnecting_slot<ResultType>; slot_type myslot(fp, _1, 0); sig.connect_extended(myslot); BOOST_CHECK(sig.num_slots() == 1); sig(); BOOST_CHECK(sig.num_slots() == 0); } // test disconnection by slot { typedef boost::signals2::signal1<ResultType, int> signal_type; typedef typename signal_type::extended_slot_type slot_type; signal_type sig; // attempting to work around msvc 7.1 bug by explicitly assigning to a function pointer ResultType (*fp)(const boost::signals2::connection &conn, int) = &disconnecting_slot<ResultType>; slot_type myslot(fp); sig.connect_extended(myslot); BOOST_CHECK(sig.num_slots() == 1); sig.disconnect(fp); BOOST_CHECK(sig.num_slots() == 0); } }
void benchmark_invocation(unsigned num_connections) { static const unsigned num_invocations = 1000000; Signal signal; std::cout << num_connections << " connections, invoking " << num_invocations << " times: "; unsigned n; for(n = 0; n < num_connections; ++n) { signal.connect(myslot()); } { boost::progress_timer timer; unsigned i; for(i = 0; i < num_invocations; ++i) { signal(0); } } }
void benchmark_connect_disconnect() { static const unsigned num_connections = 1000000; std::vector<typename connection_type<Signal>::type> connections(num_connections); Signal signal; std::cout << "connecting " << num_connections << " connections then disconnecting: "; unsigned n; { boost::progress_timer timer; for(n = 0; n < num_connections; ++n) { connections.at(n) = signal.connect(myslot()); } for(n = 0; n < num_connections; ++n) { connections.at(n).disconnect(); } } }
void AcquisitionPortManager::createList() { int size = SettingsManager::globalInstance()->getAc_PortSize(); qDebug()<<"SettingsManager::globalInstance()->getAc_PortSize()"<<SettingsManager::globalInstance()->getAc_PortSize(); QString map; for(int i = 0;i < size;i++){ AcquisitionPort* acquisitionPort; acquisitionPort = new AcquisitionPort(); connect(acquisitionPort,SIGNAL(signalwriteSerialPort(QByteArray)),this,SLOT(myslot(QByteArray))); map = SettingsManager::globalInstance()->getAcquisitionPort("AcquisitionPort"+QString::number(i+1,10)); if(!map.isEmpty()){ acquisitionPort->setACID(i+1);//记录下在文件中的 顺序编号 if(map.split(",").at(1).toInt() == 0){ m_SensorTypeacquisitionPort.insertMulti(map.split(",").at(0).toUInt(),acquisitionPort); }else if(map.split(",").at(1).toInt() == 1){ m_SwitchValueacquisitionPort.insertMulti(map.split(",").at(0).toUInt(),acquisitionPort); } } } }
void benchmark_new_tracked_invocation(unsigned num_connections) { static const unsigned num_invocations = 1000000; new_signal_type signal; std::cout << "boost::signals2::signal, " << num_connections << " connections, tracking enabled, invoking " << num_invocations << " times: "; boost::shared_ptr<int> trackable_ptr(new int(0)); unsigned n; for(n = 0; n < num_connections; ++n) { new_signal_type::slot_type slot((myslot())); slot.track(trackable_ptr); signal.connect(slot); } { boost::progress_timer timer; unsigned i; for(i = 0; i < num_invocations; ++i) { signal(0); } } }
MyWidget::MyWidget() { SmallWidget* smallWidget = new SmallWidget; connect( smallWidget, SIGNAL( mysignal() ), this, SLOT(myslot()) ); smallWidget->EmitSignal(); }