12/12/2023 0 Comments Add text to status bar access 2010![]() Go back and read my previous post again and implement what I wrote. The string "ui->statusbar->showMessage( const QString & )" doesn't translate to anything the MOC compiler has generated, so the connect() fails at runtime (and you should see a message in your debugger output that says exactly that). If it finds a match, it makes the actual connection between object instances and function pointers. At runtime, the boilerplate code generated by the MOC compiler tries to match these strings up with actual signals and slots defined for the two objects that you are trying to connect. The particular form of the connect() statement you are using takes the arguments to the SIGNAL() and SLOT() macros and turns them into quoted strings. The connect() argument that preceeds the SLOT() macro (called "receiver" in the QObject::connect() documentation) is the specific QObject instance which contains the function to be called. The SLOT() macro takes as its argument the function signature of the slot you want to be called, not the call to the function itself. It will compile because of the way the SLOT() macro is implemented, but at runtime it won't do anything because the syntax is wrong. This is some sort of hybrid of a function declaration and a function call. To copy to clipboard, switch view to plain text mode ![]() The main window's slot should look something like this: So if you want a widget in one of your tabs to send a string (message) back to your main window so the main window can display it in the status bar, then you need do do several things:ġ - define a signal in your widget with a suitable name (sendStatus maybe) and a QString argument: void sendStatus( const QString & message )Ģ - define a slot in your MainWindow class with the same signature (void displayStatusMessage( const QString & message ))ģ - implement code in this slot to display the string argument (message) in the status barĤ - when you create the widget for the tab, connect the widget's signal to the main window's slot.ĥ - when your widget wants to display a status message, call "emit sendStatus( "Here is a message" ) " Since that signal is now connected to the main window's slot, the slot will take care of displaying it If a class emits a signal with no arguments, the signal / slot mechanism can't just make something up to put in the argument defined for the slot it is connected to. In other words, your slot can't be defined with an argument that does not exist in the signal (like your 'message' argument). The C++ function signature for a slot must match the function signature for the signal. Look at the Qt examples to see how they are used in real code. If you have any problems with the registration process or your account login, please contact us.Ĭonnect ( tab class, SIGNAL tab class signal "finshed", MainWindow class, SLOT set "statusBar (message )Īgain, you need to read the Qt documentation on signals and slots so you can understand how they work. Registration is fast, simple and absolutely free so please, join our community today! By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. ![]() If you are looking for information about Qt related issue - register and post your question. Over 90 percent of questions asked here gets answered. Qt Centre is a community site devoted to programming in C++ using the Qt framework. Select the forum that you want to visit from the selection below. Passing message to MainWindow status bar - using connectīefore you can post: click the register link above to proceed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |