5

Porting VS2010 project in QT .

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

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 -> On Main application window in

MESSAGE_MAP

we have

ON_MESSAGE( WM_NOTICE, OnAddMessage )
  • where WM_NOTICE = WM_USER+1;

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

  • ‘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) 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 );
}

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. 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

samprat
  • 2,150
  • 8
  • 39
  • 73
  • Hi Guys, I am really clueless , Can someone please give me an hint how to do that? – samprat Dec 03 '13 at 13:29
  • What `WM_MULTIBOXMESSAGE` is? – Evgeny Timoshenko Dec 03 '13 at 13:36
  • HI JOnny, it is just some #defined variable declared in some files. My main concerned here is how would I send message to Main Application in QT – samprat Dec 03 '13 at 13:43
  • HI Jonny, it is just some #defined variable declared in some files. it is Used to define private messages for use by private window classes, usually of the form WM_USER+x, where x is an integer value. so here it is WM_MULTIBOXMESSAGES WM_USER+ 1 – samprat Dec 03 '13 at 13:48
  • Possible duplicate of [Get HWND on windows with Qt5 (from WId)](http://stackoverflow.com/questions/14048565/get-hwnd-on-windows-with-qt5-from-wid). – IInspectable Dec 03 '13 at 16:51
  • Why don`t you want do it with signal/slot? Or it`s so complex in this project? – Guinness Dec 06 '13 at 13:03
  • HI Guisness, Thansks for reply.. Signal and slot will not be complicate but as I read somewhere it says its an event and generallys its not a good idea to replace it with signals /slots. Moreover I havnt completely understood what that piece of code is actually doing? Can someone please expalin me in layman's language what does this actually do "SendMessage( dialog_->m_hWnd, WM_MULTIBOXMESSAGE, 0, 0 );" ? as far as I know it sends the message into main dialog window // am I right? – samprat Dec 06 '13 at 14:11
  • http://qt-project.org/doc/qt-4.8/eventsandfilters.html – Dmitry Sazonov Dec 08 '13 at 09:52
  • can some please provide me a small example . I have read lots of tutorials but could not able to get – samprat Dec 11 '13 at 18:53

1 Answers1

0

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();
}

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.

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)

George Y.
  • 11,307
  • 3
  • 24
  • 25
  • Hi George, thanks for the reply, well I guess I can do this way , So I will give it a try and will let you know. Earlier today I was trying to to emit the signal from add function and have defined the connect in pmainwindow . so let see how far i go with that ..and thanks again for the help – samprat Dec 15 '13 at 14:54