Hello,

In my application, I have declared in the header file:

Qt Code:
  1. QWidget *activeWidget
To copy to clipboard, switch view to plain text mode 

activeWidget basically represents the QWidget in my application which has input focus. In my Edit menu, I have an option called Paste, and upon clicking that I want the text from the clipboard to be pasted into the activeWidget, which can be a reference to either QLineEdit or QPlainTextEdit. However, this code is incorrect:

Qt Code:
  1. connect(actionPaste, SIGNAL(triggered()), activeWidget, SLOT(paste()));
To copy to clipboard, switch view to plain text mode 

So, I have a function in my program called paste(). The new connection script is like this:

Qt Code:
  1. connect(actionPaste, SIGNAL(triggered()), this, SLOT(paste()));
To copy to clipboard, switch view to plain text mode 

In the paste() function, I want to use typeid() to determine the type of the activeWidget pointer, which can be either QLineEdit or QPlainTextEdit. Both support the paste() slot. So, I was thinking of doing something like:

Qt Code:
  1. activeWidget = someQLineEditWidget;
  2.  
  3. ...
  4.  
  5. void MyApp::paste() {
  6. qobject_cast<typeid(activeWidget*)>(activeWidget)->paste()
  7. }
To copy to clipboard, switch view to plain text mode 

So what I am trying to do is to find the type of widget activeWidget is (in this example, QLineEdit) during runtime using typeid(), and then cast activeWidget to that type, and use the paste() function of the QLineEdit. But with that code I get a bunch of errors :

activeWidget cannot appear in a constant-expression
'typeid' operator cannot appear in a constant-expression
I know I can just check the type using "if" and "else" tags, but I want to try using typecasting as well, as it could be useful in the future.

Thanks in advance,
codeslicer