久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='NgVSL'></tfoot>
    <legend id='NgVSL'><style id='NgVSL'><dir id='NgVSL'><q id='NgVSL'></q></dir></style></legend>

    <small id='NgVSL'></small><noframes id='NgVSL'>

    • <bdo id='NgVSL'></bdo><ul id='NgVSL'></ul>
      <i id='NgVSL'><tr id='NgVSL'><dt id='NgVSL'><q id='NgVSL'><span id='NgVSL'><b id='NgVSL'><form id='NgVSL'><ins id='NgVSL'></ins><ul id='NgVSL'></ul><sub id='NgVSL'></sub></form><legend id='NgVSL'></legend><bdo id='NgVSL'><pre id='NgVSL'><center id='NgVSL'></center></pre></bdo></b><th id='NgVSL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NgVSL'><tfoot id='NgVSL'></tfoot><dl id='NgVSL'><fieldset id='NgVSL'></fieldset></dl></div>

      1. 設計模式、Qt 模型/視圖和多線程

        Design Pattern, Qt Model/View and multiple threads(設計模式、Qt 模型/視圖和多線程)
          <tbody id='kISEE'></tbody>

        <i id='kISEE'><tr id='kISEE'><dt id='kISEE'><q id='kISEE'><span id='kISEE'><b id='kISEE'><form id='kISEE'><ins id='kISEE'></ins><ul id='kISEE'></ul><sub id='kISEE'></sub></form><legend id='kISEE'></legend><bdo id='kISEE'><pre id='kISEE'><center id='kISEE'></center></pre></bdo></b><th id='kISEE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='kISEE'><tfoot id='kISEE'></tfoot><dl id='kISEE'><fieldset id='kISEE'></fieldset></dl></div>
            • <bdo id='kISEE'></bdo><ul id='kISEE'></ul>

              • <tfoot id='kISEE'></tfoot>

                1. <small id='kISEE'></small><noframes id='kISEE'>

                  <legend id='kISEE'><style id='kISEE'><dir id='kISEE'><q id='kISEE'></q></dir></style></legend>
                2. 本文介紹了設計模式、Qt 模型/視圖和多線程的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在創建一個顯示市場數據并以其他形式使用它的應用程序.我將市場數據存儲在地圖中說std::map.讓我舉一個如何使用這張地圖的用例.

                  I am creating an application which displays the market data and uses it in some other forms too. I store market data in a map say std::map<tickerId, StockData>. Let me give one used case of how this map can be used.

                  1. 網絡在時間 t 發送一個封裝股票數據的數據包.updatePrice(tickerId, latestPrice)
                  2. 更新地圖中的股票數據.現在,多個線程可以訪問/更新數據.因此必須鎖定映射以進行線程安全操作.這是第一個問題,我是否也需要鎖定底層數據以進行更新?
                  3. 新股票數據有多種用途,比如 IBM 的價格更新,然后我需要更新我投資組合中 IBM 的價值.以及在屏幕上顯示新數據.并且可以同時使用多個其他用途.updatePosition(tickerId, price)updateStockScreen(tickerId, price).此外,將 GUI 更新與位置更新分開也很重要,因為 GUI 不是應用程序的主要優勢.
                  4. 我只是對如何實現這種類型的設計感到困擾.我在 QT 中閱讀了模型/視圖設計以顯示數據,但如果視圖線程從同一地圖讀取,則必須將其鎖定.這會導致設計緩慢/低效.每次視圖從模型中讀取時,都需要鎖定模型.這在實時 GUI 中是首選嗎?
                  5. 總而言之,我將許多不同的對象存儲為地圖.并且對象是實時更新的.我需要更新它們,然后在不同的位置使用它們.如果有人能給我一個關于如何實現此類設計的小例子,那就太好了.
                  1. network sends a data packet encapsulating the stock Data at time t. updatePrice(tickerId, latestPrice)
                  2. update the stock data in the map. Now, multiple threads can access/update the data. So the map has to be locked for thread-safe operations. Here is the first question, do I need to lock the underlying data too for updates?
                  3. There are multiple uses of the new stock data, say, there is a price update on IBM, then I need to update the value of IBM in my portfolio. As well as display the new data on a screen. And there can be several other simultaneous uses.updatePosition(tickerId, price) and updateStockScreen(tickerId, price). Also, separting Gui updates from position update is important as GUI is not the main strength of the application.
                  4. I am just troubled about how to implement this type of design. I read about Model/View Design in QT to display data but if View thread reads from the same map, it has to be locked. This leads to an slow/inefficient design. Every time view reads from the model, the model needs to be locked. Is this preffered in real-time GUIs?
                  5. To summarize, I have stored a lot of different objects as maps. And objects are updated in realtime. I need to update them and then use them at various locations. It would be great if someone can give me a small example on how to implement such designs.

                  對有用書籍的一些參考也受到贊賞.

                  Some references to useful books are appreciated too.

                  我是新手,試圖用自己的知識取得太多成就,所以如果我問了愚蠢/格式錯誤的問題,請原諒我.

                  I am new and trying to achieve too much with my little knowledge so forgive me if I have asked stupid/ill-formed questions.

                  謝謝濕婆

                  推薦答案

                  從概念上講,您希望模型在一個線程上,而視圖在另一個線程上,我曾研究過這一點.

                  It sounds conceptually like you want the model on one thread and the view on another, which I looked into at one point.

                  如果是這樣...并且您的模型通過視圖小部件是只讀的,那么是的,您必須鎖定.我認為這樣做會破壞模型/視圖分離提供的解耦"的優雅.但它可以工作.

                  If so...and your model is read-only through the view widget then yes, you have to lock. I'd argue that doing so undermines the elegance of the "decoupling" provided by the model/view separation. But it could be made to work.

                  但是...如果您的模型是通過視圖讀寫的,則不可能完全正確執行,因為通知槽的排隊性質.這是我在 qt-interest 郵件列表上關于該主題的郵件列表對話的存檔:

                  However...if your model is read-write through the view it's not possible to do correctly at all because of the queued nature of the notification slots. Here's an archive of a mailing list conversation I had on the qt-interest mailing list on the topic:

                  http://blog.hostilefork.com/qt-model-view-不同的線程/

                  簡短的版本是我認為模型不可行
                  在非 GUI 線程上進行修改...無論模型是否
                  數據已被讀/寫鎖保護.如果我在收集什么
                  是正確的,那么 Qt 可能應該斷言一個模型和
                  它的視圖具有相同的線程關聯(現在似乎沒有這樣做)"

                  "The short version is that I don't think it's feasible for a Model to
                  be modified on a non-GUI thread...regardless of whether the model's
                  data has been protected with read/write locks. If what I'm gathering
                  is correct, then Qt should probably have an assert that a model and
                  its view have the same thread affinity (it doesn't seem to do that now)"

                  隨后由 KDE 開發人員進行的單元測試驗證了這一點.

                  A subsequent unit test by a KDE developer verified this.

                  我覺得解決這個問題的最好方法是將模型和視圖保持在同一線程上,并且只在 GUI 線程中修改模型.所以如果工作線程希望改變它,那么它應該使用一個信號.

                  I feel the best way to work around this is to keep the model and the view on the same thread, and only modify the model in the GUI thread. So if the worker thread wishes to change it then it should use a signal.

                  工作人員是否需要保留自己創建模型的數據副本(或者是否需要在用戶通過視圖更改模型時收到通知以使其保持最新狀態)取決于您的應用.如果我理解正確的話,聽起來您可能只需通過信號/插槽傳送更新并將它們忘記在工作人員身上就可以逃脫...

                  Whether the worker needs to keep their own copy of the data from which the model was created (or if it needs to get notifications to keep that up to date when the user changes the model through the view) depends on your app. If I understand you correctly, it sounds like like you could probably get away with just ferrying the updates through signal/slots and forgetting them on the worker...

                  這篇關于設計模式、Qt 模型/視圖和多線程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  read input files, fastest way possible?(讀取輸入文件,最快的方法?)
                  The easiest way to read formatted input in C++?(在 C++ 中讀取格式化輸入的最簡單方法?)
                  Reading from .txt file into two dimensional array in c++(從 .txt 文件讀取到 C++ 中的二維數組)
                  How to simulate a key press in C++(如何在 C++ 中模擬按鍵按下)
                  Why doesn#39;t getline(cin, var) after cin.ignore() read the first character of the string?(為什么在 cin.ignore() 之后沒有 getline(cin, var) 讀取字符串的第一個字符?)
                  What is the cin analougus of scanf formatted input?(scanf 格式輸入的 cin 類比是什么?)

                  • <small id='43w87'></small><noframes id='43w87'>

                          <tfoot id='43w87'></tfoot>
                        1. <legend id='43w87'><style id='43w87'><dir id='43w87'><q id='43w87'></q></dir></style></legend>
                            <tbody id='43w87'></tbody>
                            <bdo id='43w87'></bdo><ul id='43w87'></ul>
                            <i id='43w87'><tr id='43w87'><dt id='43w87'><q id='43w87'><span id='43w87'><b id='43w87'><form id='43w87'><ins id='43w87'></ins><ul id='43w87'></ul><sub id='43w87'></sub></form><legend id='43w87'></legend><bdo id='43w87'><pre id='43w87'><center id='43w87'></center></pre></bdo></b><th id='43w87'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='43w87'><tfoot id='43w87'></tfoot><dl id='43w87'><fieldset id='43w87'></fieldset></dl></div>

                          • 主站蜘蛛池模板: 亚洲精品字幕 | 男女羞羞视频在线免费观看 | 黄视频免费 | 真人毛片 | 免费在线观看一区二区 | 综合久 | 手机在线一区二区三区 | 国产精品久久久久久久久久三级 | 美女爽到呻吟久久久久 | 国产精品久久视频 | 四虎影院免费在线 | 国产精品毛片在线 | av影片在线 | m豆传媒在线链接观看 | 久久久久久免费毛片精品 | 国产精品亚洲一区二区三区在线观看 | 国产精品久久一区 | 欧美一级免费看 | 午夜精品91 | 欧美在线小视频 | 国产美女高潮 | 久久久人成影片免费观看 | 久久精品中文字幕 | 91影片| 91资源在线观看 | 亚洲国产精久久久久久久 | 欧美色综合一区二区三区 | 亚洲国产中文字幕 | 亚洲综合无码一区二区 | 亚洲 欧美 另类 日韩 | 国产乱码精品一区二区三区忘忧草 | 99视频在线免费观看 | 国产亚洲精品美女久久久久久久久久 | 久久久久久综合 | 91精品国产综合久久香蕉麻豆 | 日本三级做a全过程在线观看 | 天天躁日日躁狠狠很躁 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 婷婷久久综合 | 日一区二区 | 亚洲精品久 |