Access and inheritance
-
@mrjj Hi,
Yes. The book also shows the code for that.
I know I can add more options to that, for instance, to have five buttons in the context menu rather than that three ones. But by the sentence the author said, I though there should be another way to have a more advanced context menu by re-implementing the virtual protected method when mentioned earlier.By the way, don't you have that book?
-
@tomy
Hi
Well the menu already have both shortcut and icon so not sure what else could be added.
There is no "more advanced" menu possible by overwriting contextMenuEvent as
you can just 100% the same just altering
void MainWindow::createActions()
to show what you want.yes, i have it as PDF. did read most of it way back.
-
Thank you very much. I was too much stuck in a QML program's problem, sorry for the delay.
If you run the program, even by the latest version of Qt Creator and on a sophisticated and fancy operating system like Windows 10, you see the program still looks old, as though we are in 2000 using it.
Is it because of the code? If so, what parts can be updated, please? -
@tomy
Hi
Nope its just how the QWidgets look.
If you change the icons to flat style,
it will look more "modern"You could use something like
https://github.com/laserpants/qt-material-widgets
if you want to go all in for "modern" look. -
@mrjj said in Access and inheritance:
The truth is, if a base class do not do anything in its constructor, nothing bad will happen not calling it.
Just for completeness:
If the base class has a default constructor, and it's not called explicitly in the derived class' constructor the compiler is going to generate code to call it implicitly. Omitting it in the initializer list means nothing here, asQMainWindow()
is going to be called either way. If the base class does not have a default constructor, and there's no call to the parent's constructor then this is going to generate a compile error, as the compiler has no idea what to do. -
@kshegunov
Hi,If the base class has a default constructor, and it's not called explicitly in the derived class' constructor the compiler is going to generate code to call it implicitly. Omitting it in the initializer list means nothing here, as
QMainWindow()
is going to be called either way.Is it true for the Qt Creator compiler too? (I think so)
If the base class does not have a default constructor, and there's no call to the parent's constructor then this is going to generate a compile error, as the compiler has no idea what to do.
Can we conclude this way that, when the base class doesn't have a constructor, in either way, whether the subclass calls the parent's constructor (!) or it doesn't, we will get an error?
-
@tomy said in Access and inheritance:
Is it true for the Qt Creator compiler too? (I think so)
Qt Creator is not a compiler, it uses some compiler (whatever you've configured), but yes, it's true for all compiler, as this is standard (and required) behaviour for C++.
Can we conclude this way that, when the base class doesn't have a constructor, in either way, whether the subclass calls the parent's constructor (!) or it doesn't, we will get an error?
No. Not defining a class constructor means the compiler generates a default one for you (unless specifically told otherwise). If you haven't defined a constructor in the base class, then the derived class is going to implicitly call the automatically generated one.
-
So we will never have to call the base class's constructor from the subclass, because if there is an explicit constructor for the base class, the compiler calls (implicitly) for us (with the absence of an explicit call from us), and if there is no constructor for the base class, the compiler creates a default one and implicitly calls that in the subclass. Hence, we had better never involve ourselves with calling a base class's constructor directly (from the subclass)! :) :)
-
@tomy
Hi
The automatic version is only for a default constructor.
As soon as base class constructor takes parameters, it must be called from subclass as compiler cannot
know how to obtain the parameters to give to base class.
However the compiler will tell you that. -
What @mrjj said, plus the moment you define a constructor, the compiler stops generating for you. Thus if you define a constructor with parameters, the compiler will not generate a default constructor for you. Beautiful system, right? :)
-
If you change the icons to flat style, it will look more "modern"
Hi,
The example you posted look very modern and stylish, but too advanced for me now. Thank you.
I like to go step by step. So for the icons, I must download some "flat .png related files" from the Internet and substitute the old ones with these. Right? -
@tomy
Hi
Yes, that could be the first step.
Maybe a bit of stylesheet to make QToolbar more flat to fit the new icons.
I dont have an image of spreadsheet app around so im not sure what else you can
do currently. will write of get any other ideas. -
Beautiful system, right? :)
Right. :)
Yes, that could be the first step.
Maybe a bit of stylesheet to make QToolbar more flat to fit the new icons.
I dont have an image of spreadsheet app around so im not sure what else you can
do currently. will write of get any other ideas.Hi, Thanks. So I need to lookup "stylesheet".
-
-
@mrjj Hi,
I created a new project called MySpreadsheet and added a few more options to the context menu and renewed the icons to flat ones.
Now when I run the project, it runs normally, but when we close it, the follwoing message is written in the Application Output window:Starting D:\Projects\Qt\MySpreadsheet\MySpreadsheet\build-MySpreadsheet-Desktop_Qt_5_12_0_MinGW_64_bit-Debug\debug\MySpreadsheet.exe...
FTH: (243752): *** Fault tolerant heap shim applied to current process. This is usually due to previous crashes. ***
The program has unexpectedly finished.
The process was ended forcefully.
D:/Projects/Qt/MySpreadsheet/MySpreadsheet/build-MySpreadsheet-Desktop_Qt_5_12_0_MinGW_64_bit-Debug/debug/MySpreadsheet.exe crashed.What is the problem please?
Is it not related to the .pro file, please?