Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What bridges do you need? </p> <p>You can use all the Qt container classes with std algorithms. Most of the time I prefer the Qt container classes because I'm sure they use the copy-on-write idiom (constant time operation). Qt's foreach function creates a copy of the container so its nice that you know for sure it is a constant time operation. </p> <p>If the Qt signal slot mechanism is to slow you can switch to the boost alternative. The great thing about Qt signal/slot is the signal/slot connection between two threads.</p> <p>QtConcurrent works great with BOOST.Lambda</p> <hr> <p>For "shared" child-parent relationship I use this helper function.</p> <pre><code>template &lt;class Object&gt; static boost::shared_ptr&lt;Object&gt; makeSharedObject() { using namespace boost; using namespace boost::lambda; return boost::shared_ptr&lt;Object&gt;( new Object(), bind( &amp;Object::deleteLater, _1 ) ); } </code></pre> <hr> <p>Qt containers are not supported by Boost.serialize, you'll have to write the serialize functions yourself. I would love a bridge between the Qt streaming classes and Boost.archive.</p> <p>Here is my QList serialization template you can figure out the rest of them ...</p> <pre><code>///\file document is based on "boost/serialization/list.hpp" namespace boost { namespace serialization { //--------------------------------------------------------------------------- /// Saves a QList object to a collection template&lt;class Archive, class U &gt; inline void save(Archive &amp;ar, const QList&lt; U &gt; &amp;t, const uint /* file_version */ ) { boost::serialization::stl::save_collection&lt; Archive, QList&lt;U&gt; &gt;(ar, t); } //--------------------------------------------------------------------------- /// Loads a QList object from a collection template&lt;class Archive, class U&gt; inline void load(Archive &amp;ar, QList&lt;U &gt; &amp;t, const uint /* file_version */ ) { boost::serialization::stl::load_collection&lt; Archive, QList&lt;U&gt;, boost::serialization::stl::archive_input_seq&lt;Archive, QList&lt;U&gt; &gt;, boost::serialization::stl::no_reserve_imp&lt; QList&lt;U&gt; &gt; &gt;(ar, t); } //--------------------------------------------------------------------------- /// split non-intrusive serialization function member into separate /// non intrusive save/load member functions template&lt;class Archive, class U &gt; inline void serialize(Archive &amp;ar, QList&lt;U&gt; &amp;t, const uint file_version ) { boost::serialization::split_free( ar, t, file_version); } } // namespace serialization } // namespace boost BOOST_SERIALIZATION_COLLECTION_TRAITS(QList) </code></pre> <hr> <p>If you want Boost.Bind to handle QPointer as a normal pointer (like shared_ptr):</p> <pre><code>namespace boost { template&lt;typename T&gt; T * get_pointer(QPointer&lt;T&gt; const&amp; qPointer) { return qPointer; } } </code></pre> <hr> <p>Using <code>QIODevice</code> where a <code>std::stream</code> is needed</p> <pre><code>namespace boost { namespace iostreams { class IoDeviceSource { public: typedef char char_type; typedef source_tag category; explicit IoDeviceSource(QIODevice&amp; source) : m_source(source) { } std::streamsize read(char* buffer, std::streamsize n) { return return m_source.read(buffer, n); } private: QIODevice&amp; m_source; }; class IoDeviceSink { public: typedef char char_type; typedef sink_tag category; explicit IoDeviceSink(QIODevice&amp; sink) : m_sink(sink) { } std::streamsize write(const char_type* buffer, std::streamsize n) { return m_sink.write(buffer, n); } private: QIODevice &amp;m_sink; }; class IoDeviceDevice { public: typedef char char_type; typedef seekable_device_tag category; explicit IoDeviceDevice(QIODevice&amp; device) :m_device(device) { } std::streamsize write(const char_type *buffer, std::streamsize n) { return m_device.write(buffer, n); } std::streamsize read(char* buffer, std::streamsize n) { return m_device.read(buffer, n); } stream_offset seek(stream_offset off, std::ios_base::seekdir way) { using namespace std; stream_offset next(0); if(way==ios_base::beg) { next = m_device.pos(); } else if(way==ios_base::cur) { next = m_device.pos() + offset; } else if(way==ios_base::end) { next = m_device.size() -1 + offset; } else { throw ios_base::failure("bad seek direction"); } if( !m_device.seek(next) ) { throw ios_base::failure("bad seek offset"); } return m_device.pos(); } private: QIODevice &amp;m_device; }; } } </code></pre> <p><strong>Example</strong></p> <pre><code>#include &lt;iostream&gt; #include &lt;QFile&gt; #include &lt;boost/iostreams/stream.hpp&gt; #include "iodevicestream.h" int main(int argc, char *argv[]) { namespace io = boost::iostreams; QVector&lt;int&gt; data; QFile fl("temp.bin"); fl.open(QIODevice::ReadWrite); io::stream&lt;io::IoDeviceDevice&gt; inoutput( fl ); std::copy(data.begin(), data.end(), std::ostream_iterator&lt;int&gt;(inoutput, "\n")); inoutput.flush(); inoutput.seekg(0, std::ios_base::beg); std::cout &lt;&lt; inoutput; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload