在Qt中相当于MFC的SendMessage [英] SendMessage of MFC equivalent in Qt

查看:516
本文介绍了在Qt中相当于MFC的SendMessage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在QT中移植VS2010项目.

Porting VS2010 project in QT .

我想我之前的帖子不太清楚,所以我在这里再次解释.

I guess, I wasn’t very clear with my earlier post so here I am explaining it again.

问题是..我有很多子Qdialog窗口,当用户单击时它们会生成一些消息.我希望这些消息位于我的主应用程序"窗口的QTablewidget中.
现在,正如一些成员建议的那样,我应该研究VS2010中的情况,并尝试在QT中进行复制.所以这是我的设计..请让我知道您的建议/批评.

The issue is .. I have lots of sub Qdialog windows which when user click generates some messages. I want those messages to be on my QTablewidget of my main Application window.
Now As suggested by some members that I should look how things have done in VS2010 and try to replicate same in QT . So Here is my design .. Please let me know your suggestion /criticism.

1)与2010->在

1) vs 2010 -> On Main application window in

MESSAGE_MAP

我们有

ON_MESSAGE( WM_NOTICE, OnAddMessage )

  • 其中WM_NOTICE = WM_USER + 1;
  • 在QT中做同样的事情,我需要signal和slot.像

    doing same in QT I need signal and slot . so Something like

    connect( sender , SIGNAL(QtSingleApplication::messageReceived ( const QString &message )  ) , this , SLOT ( on_add_message( const QString & message ) );
    

    现在我应该在这里替换

    • 发件人"? ,谁将是我的寄件人?
    • SIGNAL(QtSingleApplication :: messageReceived)对吗?
    • 插槽-这里没有问题..我可以在其中实现该代码 会将消息按排序顺序放在QTable widegt中.
    • ‘sender’ ? , who will be the sender in my case ?
    • SIGNAL (QtSingleApplication::messageReceived ) is right ?
    • Slot — there is no issue here .. I can implement that code in which I will place the message in QTable widegt in sorting order.

    2)现在,如果我查看使用VC ++开发的现有项目的内部QDialog窗口源代码, 他们有类似的东西

    2) Now if I look into inner QDialog windows source code of existing project which was developed in VC++ they have something like

    void Message_information::add( const SMS& message )
    {
    //SMS is a  structure  and fields are SYSTEMTIME, Enum , CString
     CCriticalSection critical_section;
    CSingleLock   lock( &critical_section, true );
    messages_.insert( message ); // where messages_ is an object std::multiset
    
    SendMessage( dialog_->m_hWnd, WM_MULTIBOXMESSAGE, 0, 0 );
    }
    

    现在在Qt中做同样的事情

    Now doing same in Qt

    void Message_information::add( const SMS& message )
    {
      QMutex mutex;
      mutex.lock();
    messages_.insert( message ); // where messages_ is an object std::multiset
    
    //SendMessage( dialog_->m_hWnd, WM_MULTIBOXMESSAGE, 0, 0 );
    QtSingleApplication::sendMessage ( // send multiset values here   );
    
    }
    

    1. 我应该在SendMessage中添加什么参数? IS实际上是sendMessage 是正确的函数吗?
    1. What paramemter should I Add in SendMessage? IS infact sendMessage is correct function to call?

    此添加"功能在其他地方被调用. 我知道这听起来与其他问题完全相同,我已经查看了部分成员的链接,但很抱歉,我无法掌握很多内容. - 任何建议或批评都可能对我有所帮助.

    this ‘add’ function is being called somewhere else . I know this sounds duplicate of other questions and I have looked into the link provided my some members but I am sorry I couldn’t able to grasp much. — Any suggestion or criticism might help me .. hanks a lot for al the help

    推荐答案

    在您的情况下,您似乎有多个QDialog,它们应该将某些内容发送到单个MainApplication,对吗?

    It appears that in your case you have multiple QDialogs, which should send something to a single MainApplication, right?

    您是否有特定的原因无法通过直接函数调用来做到这一点?如:

    Is there a particular reason you cannot do it via direct function call? Such as:

    MyMainWindows * pMainWindow;
    
    ...
    
    void MyMainWindows::addMessage( const SMS& message )
    {
    ...
    }
    
    void Message_information::add( const SMS& message )
    {
      QMutex mutex;
      mutex.lock();
      messages_.insert( message ); // where messages_ is an object std::multiset
    
      pMainWindow->addMessage( messages_ );
      mutex.unlock();
    }
    

    这与直接连接的信号插槽具有相同的效果,并且接近SendMessage的作用.

    This would have the same effect as signal-slot with direct connection, and close to what SendMessage does.

    如果有任何特殊原因无法使用此构造,请确定它,因为它会影响应使用哪种信号/插槽类型.

    If there is any particular reason you cannot use this construction, please identify it as it will make a difference what type of signal/slot you should use.

    如果您对此结构很好,但希望使用信号插槽而不是直接调用,也请告知我们,因为将其转换为信号插槽代码非常容易(只要您的应用程序正在运行事件循环和代码生成信号继承自QObject)

    If you are fine with this construction but would like to use signals-slots instead of direct calls, also please let us know as it is fairly easy to convert this into signal-slot code (as long as your app is running the event loop and the code generating signals is inherited from QObject)

    这篇关于在Qt中相当于MFC的SendMessage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆