|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
hi all,
i am change my exe icon its working fine with icon which have single stage icon.
but if i select a icon file that have multiple size stages in icon file, icon not reflect on exe.
HANDLE handle = BeginUpdateResource(exe_file, FALSE);
char *buffer; // buffer to store raw icon data
long buffersize; // length of buffer
int hFile; // file handle
hFile = open(ico_file, O_RDONLY | O_BINARY);
if (hFile == -1)
return; // if file doesn't exist, can't be opened etc.
// calculate buffer length and load file into buffer
buffersize = filelength(hFile);
buffer = (char *)malloc(buffersize);
read(hFile, buffer, buffersize);
close(hFile);
int icon_id=1;
UpdateResource(
handle, // Handle to executable
RT_ICON, // Resource type - icon
MAKEINTRESOURCE(icon_id), // Make the id 1
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
(buffer+22),
// skip the first 22 bytes because this is the
// icon header&directory entry (if the file
// contains multiple images the directory entries
// will be larger than 22 bytes
buffersize-22 // length of buffer
);
/////////////////////
// Again, we use this structure for educational purposes.
// The icon header and directory entries can be read from
// the file.
GROUPICON grData;
icon_id=1;
// This is the header
grData.Reserved1 = 0; // reserved, must be 0
grData.ResourceType = 1; // type is 1 for icons
grData.ImageCount = 1; // number of icons in structure (1)
// This is the directory entry
grData.Width = 32; // icon width (32)
grData.Height = 32; // icon height (32)
grData.Colors = 0; // colors (256)
grData.Reserved2 = 0; // reserved, must be 0
grData.Planes = 2; // color planes
grData.BitsPerPixel = 32; // bit depth
grData.ImageSize = buffersize - 22; // size of image
grData.ResourceID = icon_id; // resource ID is 1
UpdateResource(
handle,
RT_GROUP_ICON,
MAKEINTRESOURCE(icon_id),
// MAINICON contains information about the
// application's displayed icon
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
&grData,
// Pointer to this structure
sizeof(GROUPICON)
);
delete buffer; // free memory
// Perform the update, don't discard changes
// Write changes then close it.
if (!EndUpdateResource(handle, FALSE))
{
return ;
}
please help me where i am doing mistake.
thanks in advance.
|
|
|
|
|
Le@rner wrote: buffer = (char *)malloc(buffersize);
...
delete buffer; // free memory
let's begin with the basics: Why do you use malloc to allocate buffer and then use delete to free the memory?
|
|
|
|
|
To make life more exciting?
|
|
|
|
|
Quote: (buffer+22),
// skip the first 22 bytes because this is the
// icon header&directory entry (if the file
// contains multiple images the directory entries
// will be larger than 22 bytes
buffersize-22 // length of buffer
);
The above remark is a hint, isn't it?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
|
Thank you!
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
SOLVED
Never mind - found how to "convert " picture to text.
Is there an acceptable way to post a picture or attach a file to a post ?
I have a "debug view" I like to post.
Cheers
modified 2 days ago.
|
|
|
|
|
use imgur.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
And how about copy/paste the eliable code snippet together with "debug assertion failed" message text?
|
|
|
|
|
This is a offshoot of my last post.
I have a main, I call it parent, class constructed /defined this way :
MainWindow_Bluetooth::MainWindow_Bluetooth(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow_Bluetooth),
m_status(new QLabel),
m_console(new Console),
m_mdiarea(new QMdiArea),
m_settings(new SettingsDialog),
m_serial(new QSerialPort(this))
{
Class QMdiArea allows for constructing sub-windows objects.
Works as expected.
Class SettingDialog is one of the constructed sub_windows.
Here is its definition and addition of it to the QMdiArea:
SettingsDialog *SD = new SettingsDialog(this);
NewMdiSub(SD); NewMdiSub(SD->m_TAB_Connect);
text = " Console I/O ";
SD->m_TAB_Connect->ui->tabWidget->setTabText(0,text);
text = " DEBUG TRACE ";
SD->m_TAB_Connect->ui->tabWidget->setTabText(1,text);
text = " DEBUG ";
SD->m_TAB_Connect->ui->tabWidget->setTabText(2,text);
My task is to "close" this "SD" addition and process the closure.
Clicking "X" on "SD" results in processing this code :
( I am deliberately not using Qt terminology, immaterial for this analysis )
void SettingsDialog::closeEvent( QCloseEvent* event )
{
#ifdef RETILE
text = "\t#i#ifdef RETILE \n";
text += "TRACE START Retile mdiArea subwindows .... ";
text += " ";
text += Q_FUNC_INFO;
text += QString::number(__LINE__);
qDebug().noquote() << text;
#endif
event->accept(); text += " ";
text += "\n\t TEST send text to child";
m_TAB_Connect->ui->plainTextEdit_2->appendPlainText(text);
}
The code gets executed. as expected.
I cannot figure out if processing the above "belongs" to "SD" object or
"m_settings" object.
PLEASE
help me finding out the relations between "parent" , "SD " and "m_settings" objects.
I am NOT asking for code, just for some help with how to analyze this.
(If you decide this is Qt problem - it is NOT -
PLEASE JUST IGNORE this post, (instruction )
and save your time
no opinions / commentaries are needed / welcomed.)
Thanks, help is appreciated very much.
|
|
|
|
|
This is what I understand from the above:
1. MainWindow_Bluetooth is a class that contains various properties including m_settings . When instantiated m_settings is set to point to a new SettingsDialog .
2. SD is a pointer to a new SettingsDialog . No idea where it is created or why, since this appears to be a duplicate of m_settings .
3. In the closeEvent of SettingsDialog you create some text and pass it to m_TAB_Connect , presumably to be displayed somewhere. It is not possible to say whether this is called by SD or m_settings since other parts of the code are not present.
|
|
|
|
|
This is an offshoot of my other post
AND
if it is NOT OK for me to continue posting - there are others who are commenting negatively
about my too many posts"
PLEASE
DO NOT REPLY
I do not want to waste "volunteers time ".
I am currently working on nested objects
main object ( patent _)
secondary object ( child )
next object ( child )
I am trying to pass correct parameters between them
I am debugging the flow using constructors and
it looks as the compiler / linker access / flow in sort of backwards
First trace is "next object " constructor ....
and then I get lost tracing....UP next object
is that normal ?
That is all I wanted to ask.
Thanks
|
|
|
|
|
I assume your question is about the order of initialization of compound objects.
#include <iostream>
using std::cout;
class level3 {
public:
level3(const std::string& name);
};
class level2 {
public:
level2(const std::string& name);
private:
level3 grandchild;
level3 favourite_grandchild;
};
class top_level {
public:
top_level(const std::string& name);
private:
level2 child;
level2 other_child;
};
top_level::top_level(const std::string& name)
: other_child("other_child") , child("child") {
cout << name << " constructor\n";
}
level2::level2(const std::string& name)
: favourite_grandchild("favourite_grandchild") , grandchild("grandchild") {
cout << name << " level2 constructor\n";
}
level3::level3(const std::string& name)
{
cout << name << " level3 constructor\n";
}
int main()
{
top_level t("top");
}
The result is this:
grandchild level3 constructor
favourite_grandchild level3 constructor
child level2 constructor
grandchild level3 constructor
favourite_grandchild level3 constructor
other_child level2 constructor
top constructor
In words: aggregate objects initialize their members in the order in which the members are declared, not in the order of initializers in the constructor of the aggregate. After initializing all members, the constructor code is run.
Mircea
|
|
|
|
|
Many thanks for helping me to analyze the problem.
I now have a better understanding what is going on and have found a part of the problem.
Here my current partial trace
19:45:53: Debugging /mnt/A_BT_DEC10/A_APR13_APR15/A_APR9_MAR7_MAR19_CLEAN/A_BT_LIBRARY/mdi/mdi ...
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
" #ifdef CONNECT START constructor A_BT_TAB_DIALOG::A_BT_TAB_DIALOG(QWidget *)"
" #ifdef CONNECT END constructor A_BT_TAB_DIALOG::A_BT_TAB_DIALOG(QWidget *)"
" #ifdef CONNECT ZTART CONSTRUCTOR SettingsDialog::SettingsDialog(QWidget *) @ line # 88"
" #ifdef CONNECT END CONSTRUCTOR SettingsDialog::SettingsDialog(QWidget *) @ line # 229"
" #ifdef CONNECT START constructor A_BT_TAB_DIALOG::A_BT_TAB_DIALOG(QWidget *)"
" #ifdef CONNECT END constructor A_BT_TAB_DIALOG::A_BT_TAB_DIALOG(QWidget *)"
" #ifdef CONNECT ZTART CONSTRUCTOR SettingsDialog::SettingsDialog(QWidget *) @ line # 88"
" #ifdef CONNECT END CONSTRUCTOR SettingsDialog::SettingsDialog(QWidget *) @ line # 229"
and it shows that both objects are "constructed " twice...
|
|
|
|
|
ADDENDUM
I am still trying to learn how to pass parameters to object.
My current "duplicating constructor" is because I am doing
it wrong.
My main object constructor is defined this way:
MainWindow_Bluetooth::MainWindow_Bluetooth(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow_Bluetooth),
m_status(new QLabel),
m_console(new Console),
m_mdiarea(new QMdiArea),
m_settings(new SettingsDialog),
m_serial(new QSerialPort(this))
{
hence I am passing settings(new SettingsDialog),
as a parameter.
SettingsDialog constructor:
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::SettingsDialog),
m_status(new QLabel),
m_TAB_Connect(new A_BT_TAB_DIALOG),
m_TAB_Ext(new A_BT_TAB_DIALOG_EXT),
m_intValidator(new QIntValidator(0, 4000000, this))
{
its in question / problem passed parameter is
m_TAB_Connect(new A_BT_TAB_DIALOG),
now for the source of this problem
I have TWO instances of SettingsDialog
and they point to TWO instances of A_BT_TAB_DIALOG
hence I end up with WRONG instances of A_BT_TAB_DIALOG
Can I modify my code to have TWO instances of A_BT_TAB_DIALOG
and make sure I point to the CORRECT instance ?
In my not so technical terminology
can I pass a parameter to
have something like
m_TAB_Connect(new A_BT_TAB_DIALOG),
m_TAB_Connect_Ext(new A_BT_TAB_DIALOG),
I am looking for a solution and I am open tor suggestions
leading to proper C++ solution.
Thanks
|
|
|
|
|
Salvatore Terress wrote: Can I modify my code to have TWO instances of A_BT_TAB_DIALOG
and make sure I point to the CORRECT instance ? What do you mean by "correct"?
In your code:
SettingsDialog::SettingsDialog(QWidget *parent) :
m_TAB_Connect(new A_BT_TAB_DIALOG), m_TAB_Ext(new A_BT_TAB_DIALOG_EXT), { If you have somewhere:
SettingsDialog obj1(parent);
SettingsDialog obj2(parent); each one of them will have their own TAB_Connect and TAB_Ext . In other words obj1.m_TAB_Connect != obj2.m_TAB_Connect .
Do you want both of them to point to the same TAB object?
Mircea
|
|
|
|
|
I am sorry - I should have deleted the _Ext .
Currently I am asking about the
variable( new object )
syntax
elsewhere.
I have a hard time finding /searching for it
I just need a verbal expiation of THIS specific form / syntax
or real reference to it.
|
|
|
|
|
If you have an object like this:
class Thing1 {
public:
Thing1 ();
} You can use it in another object:
class Composite {
public:
Composite ();
private:
Thing1* part;
};
Composite::Composite()
: part (new Thing1)
{
} In Composite , the member part is a pointer to a Thing1 . When a composite is constructed, first the program allocates on heap a new object of type Thing1 and invokes it constructor. Because constructor for Thing1 does not have any parameters there is no need for a list of parameters.
Next step:
You have another type of object Thing2 declared like:
class Thing2 {
public:
Thing2 (int param=42);
}; and the Composite object has 2 members:
class Composite {
public:
Composite ();
private:
Thing1* part;
Thing2* other_part;
}; The constructor of Composite could be:
Composite::Composite ()
: part (new Thing1) , other_part (new Thing2) {} because now the constructor for Thing1 needs a parameter but the parameter has a default value and the compiler will call the constructor with said value. Obviously, if you need a different value for the parameter, you will have to add it:
Composite::Composite ()
: part (new Thing1) , other_part (new Thing2(24) {}
Going back to the original question (which you seem to have deleted)
What you want to have is it something like:
class Composite{
public:
Composite ();
private:
Thing1 *part;
Thing1 *other_part;
{} ? Try to rephrase your question it terms of simple objects to make it easier for us to understand.
Mircea
|
|
|
|
|
Lets break this down:
1) The expression new Object creates a new instance of Object on the heap, and provides a pointer to the new object.
2) The expression foo( something ) makes a function call. We might be able to deduce that m_status() is a member function to some object, both from your descriptions elsewhere and the use of the m_ decoration, but that's not necessarily the case. It could be you are using m_ as a decoration for a menu object or a motorhome object or some other mystery object....
Together we have f(new Object) which (1) constructs a new Object on the heap, and then (2) calls a function f with a pointer to the newly constructed Object . What we don't know is if Object has a default constructor. It might not, in which case, as you observe over in the lounge, you must use f(new Object(param, ...) . There may be multiple constructors, so you'll need to check the documentation for the Object to see which one is most appropriate.
If you create an object with new , at some point delete Object should to be used to recover the allocated memory1. It's seems unlikely the the called function would do that, as it cannot know whether the pointer to Object is a pointer to a stack or heap object. Trying to delete a stack object is almost certainly going to cause Bad Things™ to happen. Maybe an immediate abort, maybe an exception gets thrown or maybe just a silent mess up of your data, with no indication that bad things have happened until some time later in the program. So you're probably better off to not use new Object as a parameter to a function. In general you should prefer a smart pointer ( Dynamic memory management - cppreference.com ) to new/delete in new development. But maybe the function does expect its parameter to be newly constructed within the parameter list and will delete before it returns? We don't know.
Footnotes:
1 This isn't strictly true. If you only create one instance of an object, the memory will be recovered when the program exits. A number of GNU C stdlib routines do this, allocating a block of memory when first called and re-using it as needed. The allocated memory is only "lost" to the executing program - assuming virtual memory and one of the usual operating systems (e.g. window, linux, macos, etc). That might not be true for some specialized use operating systems or for "stand-alone" programming environments.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Thank you, that is exactly what I was asking about.
Plain explanation,,,,
I need to digest the "pointer to the object ".
My program just broke big time , so I am busy trying find where...
I have backup , but not up - to date...
Thanks again...
PS
I need to stay away from lounge, those folks are in their own world ,,,
definitely not same as mine
|
|
|
|
|
Salvatore Terress wrote: I need to digest the "pointer to the object ".
That's worrisome. That's basic C/C++ stuff. Something any programmer with more than a few weeks experience should at least have some familiarity with. You should also understand the relationship between a pointer and a reference.
Salvatore Terress wrote: My program just broke big time , so I am busy trying find where...
I have backup , but not up - to date..
Get yourself hooked up with a version control system like Git or SVN. There are public servers for both. If you need to keep you code proprietary (or just don't wish to share), either can be set up locally. If you need a local SVN/Git server, that might be a great project for a PI. If you're using QDevelop, then a quick google suggests that it supports several Version Control systems. Even if you're the only developer, being able to review and/or revert can save you a whole bunch of time. And red faces.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Sorry, bu I need more explanations /help .
Here is my class constructor
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::SettingsDialog),
m_status(new QLabel),
m_TAB_Connect(new A_BT_TAB_DIALOG),
m_intValidator(new QIntValidator(0, 4000000, this))
{
here is a snippet of class definition
A_BT_TAB_DIALOG *m_TAB_Connect = nullptr;
you said that
new A_BT_TAB_DIALOG),
builds a pointer - to object A_BT_TAB_DIALOG
and
m_TAB_Connect(new A_BT_TAB_DIALOG),
is a function call of function
m_TAB_Connect
that is not what I thought is happening
and I hope it is not some kind of Qt "stuff"
I am reading
m_TAB_Connect(new A_BT_TAB_DIALOG),
as
passing pointer m_TAB_Connect of (new) object A_BT_TAB_DIALOG
am I wrong?
I am not trying to nitpick, but I am having an issue accessing correct instance of
the parent class AND NEED to get this terminology correct.
|
|
|
|
|
Let's try and look at this set of parameters line by line
1. Why are you calling QDialog here? That line of code creates a new QDialog object, but you do not save any pointer to it, so what is the reason for that?
QDialog(parent),
2. I assume that m_ui is declared as a pointer to a Ui::SettingsDialog which you will refer to somewhere later.
m_ui(new Ui::SettingsDialog),
3. As with point 2 you create a new object whose pointer you store in m_status .
m_status(new QLabel),
4. Possibly the same as 2 and 3 but I have no idea what m_TAB_Connect is. Is it a pointer, or a method?
m_TAB_Connect(new A_BT_TAB_DIALOG),
5. Same as comment 4.
m_intValidator(new QIntValidator(0, 4000000, this))
So without further details of the class it is impossible to say whether this is correct or not. Constructors really should do the minimal initialisation necessary to create the object, that is just setting properties that do not require callouts to other classes. Any calls to other constructors, methods, API functions etc. is generally best left to an initialisation method.
|
|
|
|
|