[solved],Issue with QVector
I am coming at this from 2 different angles but having no success with either. What I am trying to do is have a vector of 'ParsableTextEdit' which is my own type that is derived from QTextEdit. I am implementing a tab system using QTabWidget. So I have a pointer called 'currentTab', this is used to point to elements in the vector to make it the current one.
The first approach was using pointers like so:
@QVector<ParsableTextEdit *> vec;@
and appending like so:
Then when I want to make any of them the current one, I do this:
@currentTab = vec[index];@
This causes no errors and makes sense to me but I know that currentTab is not referencing the right ParsableTextEdit when I switch away from the first one because I have connected the textChanged() signal to a slot like so:
and it doesn't get fired when I switch to another index in the vector. All this really does is adds an asterisk to the tab name so I know it has been modified. It works for the first element in the vector but no others.
The other approach I took was making the vector elements plain objects like this:
Then I would do this when I am adding a new one:
@Parsable temp = ParsableTextEdit();
currentTab = &vec[vec.count -1];@
This then gives me errors like:
@QTextEdit::QTextEdit(const QTextEdit&) is private
I have no idea what that means :/
If anyone knows what is causing this, I would really appreciate the help. Please ask if more information is needed.
QObject and QObject derived classes cannot be copied. You can find a more complete explication on why it is like that in QObject's documentation.
Why are you not using QTabWidget::currentIndex or QTabWidget::currentWidget to retrieve the current widget ?
I think the reason I went for the vector to keep track of my tabs rather than that was because the currentWidget function obviously returns a QWidget. I want to have a ParsableTextEdit returned.
Am I being silly here? Do I need to have my ParsableTextEdit within a QWidget that is appended to the QTabWidget? I know it too is derived from QWidget but I shouldn't cast down?
Thanks for your reply bro
But you are getting a ParsableTextEdit. You just need to cast the returned pointer using qobject_cast. No need to have any dummy container widget
Yeah man, a little read at at the QTabWidget documentation kinda showed me how stupid I was being. Still in the process of building it that way but will mark this thread as solved soon.
Thanks for your help ;)
I am using:
@currentTab = qobject_cast<ParsableTextEdit *>(tabs->currentWidget());@
to pass a pointer to my currentTab pointer. The only reason I am doing this is because I am connecting currentTabs textChanged() signal to my SLOT.
Would you suggest I am going about it wrong?
Ok, solved... I should not be allowed near code haha
The pointer was pointing to the right thing all along. My signal and slot were the problem. It connection needs to be reestablished if pointing to another object.
Thank you for your help. Much obliged!
You only need to establish the connection once for each widget (unless you have a good reason to disconnect)
You're welcome !