Qt中MFC等价物的SendMessage [英] SendMessage of MFC equivalent in Qt

查看:14
本文介绍了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) vs 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 ) );
    

    现在我应该用什么替换这里

    now what should I replace here with

    • ‘发件人’?,在我的情况下,谁将是发件人?
    • SIGNAL (QtSingleApplication::messageReceived) 对吗?
    • 插槽——这里没有问题..我可以实现我在其中的代码将消息按排序顺序放置在 QTable widegt 中.

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

    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 中添加什么参数?是事实上的发送消息调用的函数是否正确?

    这个添加"函数正在其他地方被调用.我知道这听起来与其他问题重复,我已经查看了为我的一些成员提供的链接,但很抱歉我无法掌握太多.—任何建议或批评都可能对我有所帮助.. 非常感谢大家的帮助

    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天全站免登陆