|
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,
I am beginner trying to use win32 wdk or wdm resources in c/c++ to disable USB Suspend mode per device with specific VidPid or GUID, etc.?. Selected device never goes low power mode even if user does force it from the windows power menu. any code examples that does it, written in any language?.
|
|
|
|
|
I am asking for code assistance, I am NOT asking for opinions, to implement
"foreach" to be able to write something likes
"action-> trigger this code "
I am asking for code help to rewrite this to recursively go thru the object hierarchy until "textMatch" is found
<pre>
QString textMatch = test; QList<QAction*> pTEST = parent->findChildren<QAction *>();
foreach( auto *action, pTEST)
{
text = action->objectName();
qDebug().noquote() << text;
if(text.contains(textMatch))
{
#ifdef RETILE
text = "match found parent ";
text += parent->objectName();
text += "\n action ";
text += action->objectName();
qDebug().noquote() << text;
#endif
action->trigger();
text += " foreach match ";
qDebug().noquote() << text;
return 0;
break;
}
}
The code abiove works fine "in single stage",
I need it to iterate , using foreach preferred, but not mandatory, thru the entire tree.
PLEASE NOTE
This is an "under construction code " and will be deleted AFTER solution is found.
"actionTile_subwindows" QAction
Locals
event @0x7fffffffca20 QCloseEvent
mdiParent @0x7ffff4ea5453 QMdiSubWindow
pActions <not accessible> QList<QAction*>
pL <not accessible> QList<QObject*>
pLParent <not accessible> QList<QObject*>
pLParent_Action <not accessible> QList<QAction*>
pOBJECT 0x5d0000006e QWidget*
pTEST @0x7fffffffc550 QWidget
this "SettingsDialog" SettingsDialog
[QDialog] "SettingsDialog" QDialog
[d] @0x555555d923e0 QDialogPrivate
[parent] @0x555555de3310 QMdiSubWindow
[QWidget] @0x555555de3310 QWidget
[d] @0x5555556d1000 QMdiSubWindowPrivate
[parent] @0x555555c30e80 QWidget
[QObject] @0x555555c30e80 QObject
[QPaintDevice] @0x555555c30e90 QPaintDevice
[d] @0x555555c30ec0 QWidgetPrivate
[parent] @0x555555c64250 QMdiArea
[QAbstractScrollArea] @0x555555c64250 QAbstractScrollArea
[d] @0x5555559ff1a0 QMdiAreaPrivate
[parent] "MainWindow_Bluetooth" MainWindow_Bluetooth
[QMainWindow] "MainWindow_Bluetooth" QMainWindow
[d] @0x555555c2ed00 QMainWindowPrivate
[parent] @0x555555ccf290 QMdiSubWindow
[children] <35 items> QList<QObject*>
[0] "_layout" QMainWindowLayout
[1] @0x555555c64250 QMdiArea
[2] "SettingsDialog" SettingsDialog
[3] @0x555555cdddc0 QSerialPort
[4] "actionAbout" QAction
[5] "actionAboutQt" QAction
[6] "actionConnect" QAction
[7] "actionDisconnect" QAction
[8] "actionConfigure" QAction
[9] "actionClear" QAction
[10] "actionQuit" QAction
[11] "actionVirtual_serial_port" QAction
[12] "actionBluetooth_virtual_port" QAction
[13] "actionBluetooth" QAction
[14] "actionBluetooith_virtiual_port" QAction
[15] "actionBluetooth_service_enable" QAction
[16] "actionWinsow_control" QAction
[17] "actionWindoiw_control" QAction
[18] "actionTEST_tile" QAction
[19] "actionTEST_resize" QAction
[20] "actionTile_subwindows" QAction
[21] "actionCascade_subwindows" QAction
[22] "actionMaximize_current_subwindow" QAction
[23] "actionTEST" QAction
[24] "actionSubmenu_1" QAction
[25] "actionSubmenuy_2" QAction
[26] "actionClear_all_windoiws" QAction
[27] "actionClear_all_windiws" QAction
[28] "actionSerial_test" QAction
[29] "actionSerial_test_2" QAction
[30] "actionC_code_scan" QAction
[31] "actionSelect_MDI_subwindow_MDI_window_control" QAction
[32] "menuBar" QMenuBar
[33] "mainToolBar" QToolBar
[34] "statusBar" QStatusBar
[properties] <at least 0 items>
[methods] <20 items>
[extra]
Menu_Index 0 int
command 0x0 char*
index 8 int
index_sub 0 int
list_array @0x555555bd2370 QStringList[10]
m_TAB_CommonDebug "A_BT_TAB_DIALOG" A_BT_TAB_DIALOG
m_TAB_Connect 0x0 A_BT_TAB_DIALOG*
m_TAB_Ext 0x0 A_BT_TAB_DIALOG_EXT*
m_console @0x555555c314f0 Console
m_mdiarea @0x555555c64250 QMdiArea
m_serial @0x555555cdddc0 QSerialPort
m_settings "SettingsDialog" SettingsDialog
m_settings_RFcomm 0x0 SettingsDialog_RFcomm*
m_status @0x555555c64370 QLabel
m_ui @0x5555556735a0 Ui::MainWindow_Bluetooth
mainAction @0x555555bd24c8 QAction*[16]
result "" QString
subAction @0x555555bd23c8 QAction*[16]
subMenu @0x555555bd2448 QMenu*[16]
text " Parent console (case 7) " QString
verify @0x555555bd2570 QStringList[16]
[children] <3 items> QList<QObject*>
[0] "qt_scrollarea_hcontainer" QAbstractScrollAreaScrollBarContainer
[1] "qt_scrollarea_vcontainer" QAbstractScrollAreaScrollBarContainer
[2] @0x555555c30e80 QWidget
[properties] <at least 8 items>
[methods] <14 items>
[extra]
[children] <6 items> QList<QObject*>
[properties] <at least 59 items>
[methods] <27 items>
[0] windowTitleChanged
[nameindex] 1
[type] signal
[argc] 1
[parameter] 149
[tag] 2
[flags] 6
[localindex] 0
[globalindex] 5
[1] windowIconChanged
[nameindex] 4
[type] signal
[argc] 1
[parameter] 152
[tag] 2
[flags] 6
[localindex] 1
[globalindex] 6
[2] windowIconTextChanged
[nameindex] 6
[type] signal
[argc] 1
[parameter] 155
[tag] 2
[flags] 6
[localindex] 2
[globalindex] 7
[3] customContextMenuRequested
[nameindex] 8
[type] signal
[argc] 1
[parameter] 158
[tag] 2
[flags] 6
[localindex] 3
[globalindex] 8
[4] setEnabled
[nameindex] 10
[type] slot
[argc] 1
[parameter] 161
[tag] 2
[flags] 10
[localindex] 4
[globalindex] 9
[5] setDisabled
[nameindex] 11
[type] slot
[argc] 1
[parameter] 164
[tag] 2
[flags] 10
[localindex] 5
[globalindex] 10
[6] setWindowModified
[nameindex] 12
[type] slot
[argc] 1
[parameter] 167
[tag] 2
[flags] 10
[localindex] 6
[globalindex] 11
[7] setWindowTitle
[nameindex] 13
[type] slot
[argc] 1
[parameter] 170
[tag] 2
[flags] 10
[localindex] 7
[globalindex] 12
[8] setStyleSheet
[nameindex] 14
[type] slot
[argc] 1
[parameter] 173
[tag] 2
[flags] 10
[localindex] 8
[globalindex] 13
[9] setFocus
[nameindex] 16
[type] slot
[argc] 0
[parameter] 176
[tag] 2
[flags] 10
[localindex] 9
[globalindex] 14
[10] update
[nameindex] 17
[type] slot
[argc] 0
[parameter] 177
[tag] 2
[flags] 10
[localindex] 10
[globalindex] 15
[11] repaint
[nameindex] 18
[type] slot
[argc] 0
[parameter] 178
[tag] 2
[flags] 10
[localindex] 11
[globalindex] 16
[12] setVisible
[nameindex] 19
[type] slot
[argc] 1
[parameter] 179
[tag] 2
[flags] 10
[localindex] 12
[globalindex] 17
[13] setHidden
[nameindex] 21
[type] slot
[argc] 1
[parameter] 182
[tag] 2
[flags] 10
[localindex] 13
[globalindex] 18
[14] show
[nameindex] 23
[type] slot
[argc] 0
[parameter] 185
[tag] 2
[flags] 10
[localindex] 14
[globalindex] 19
[15] hide
[nameindex] 24
[type] slot
[argc] 0
[parameter] 186
[tag] 2
[flags] 10
[localindex] 15
[globalindex] 20
[16] showMinimized
[nameindex] 25
[type] slot
[argc] 0
[parameter] 187
[tag] 2
[flags] 10
[localindex] 16
[globalindex] 21
[17] showMaximized
[nameindex] 26
[type] slot
[argc] 0
[parameter] 188
[tag] 2
[flags] 10
[localindex] 17
[globalindex] 22
[18] showFullScreen
[nameindex] 27
[type] slot
[argc] 0
[parameter] 189
[tag] 2
[flags] 10
[localindex] 18
[globalindex] 23
[19] showNormal
[nameindex] 28
[type] slot
[argc] 0
[parameter] 190
[tag] 2
[flags] 10
[localindex] 19
[globalindex] 24
[20] close
[nameindex] 29
[type] slot
[argc] 0
[parameter] 191
[tag] 2
[flags] 10
[localindex] 20
[globalindex] 25
[21] raise
[nameindex] 30
[type] slot
[argc] 0
[parameter] 192
[tag] 2
[flags] 10
[localindex] 21
[globalindex] 26
[22] lower
[nameindex] 31
[type] slot
[argc] 0
[parameter] 193
[tag] 2
[flags] 10
[localindex] 22
[globalindex] 27
[23] updateMicroFocus
[nameindex] 32
[type] <unknown>
[argc] 0
[parameter] 194
[tag] 2
[flags] 9
[localindex] 23
[globalindex] 28
[24] _q_showIfNotHidden
[nameindex] 33
[type] <unknown>
[argc] 0
[parameter] 195
[tag] 2
[flags] 8
[localindex] 24
[globalindex] 29
[25] grab
[nameindex] 34
[type] <unknown>
[argc] 1
[parameter] 196
[tag] 2
[flags] 2
[localindex] 25
[globalindex] 30
[26] grab
[nameindex] 34
[type] <unknown>
[argc] 0
[parameter] 199
[tag] 2
[flags] 34
[localindex] 26
[globalindex] 31
[extra]
data @0x555555c30fe0 QWidgetData
[children] <4 items> QList<QObject*>
[properties] <at least 2 items>
[methods] <7 items>
[extra]
[children] <8 items> QList<QObject*>
[properties] <at least 0 items>
[methods] <8 items>
[extra]
ConnectIndex 1 int
ConnectParent "MainWindow_Bluetooth" MainWindow_Bluetooth
ConnectText " TEST SettingsDialog Constructor (emit index 1 ) " QString
m_TAB_CommonDebug 0x0 A_BT_TAB_DIALOG*
m_TAB_Connect "A_BT_TAB_DIALOG" A_BT_TAB_DIALOG
m_TAB_Ext "A_BT_TAB_DIALOG_EXT" A_BT_TAB_DIALOG_EXT
m_currentSettings @0x555555d86c88 SettingsDialog::Settings
m_intValidator @0x555555dc61c0 QIntValidator
m_status @0x555555dc5af0 QLabel
m_ui @0x555555cb7d90 Ui::SettingsDialog
pTAB "A_BT_TAB_DIALOG" A_BT_TAB_DIALOG
staticMetaObject @0x7ffff7f03560 QMetaObject
statusBar @0x555555dd75f0 QStatusBar
text " this->parent()->objectName() " QString
Inspector
Expressions
"(?<=\thci0 <no such value>
// subMenu[index] = subMenu[index]
// ->addMenu(list[index] +
SERIAL_SETUP
SetupRun
endif
// //subtempmenu = new QMenu();
//
m_ui->actionConnect
processAction
qDebug().noquote() << text;
Return Value
Tooltip
|
|
|
|
|
There's probably a nice template way to do this. But if I understand you're problem, here's a simple C++ program with multi-level tree that you may be able to adapt to your situation:
#include <vector>
#include <iostream>
class Tree {
public:
int datum;
std::vector<Tree> children;
Tree(int d) :datum(d) {}
};
void walk(Tree& t, size_t n, void fn(const Tree& t, size_t n) )
{
fn(t, n);
for(auto child: t.children)
walk(child, n+1, fn);
}
int main()
{
Tree t(0);
for(int x = 1; x < 3; ++x)
{
Tree tmp(x);
t.children.push_back(tmp);
}
for(int y = 100; y < 500; y += 100 )
{
Tree tmp(y);
t.children[0].children.push_back(tmp);
}
walk(t, 0, [](const Tree& t, size_t indent) { std::cout << std::string(indent*3, ' ') << t.datum << '\n'; });
} This processes the parent before the children, but you can reverse the lines of the walk function to do the children first, if preferred. foreach is not part of the C++ standard, but the ranged for loop has been since C++-11, so your compiler almost certainly supports it. Whether QT containers will work with ranged for loops is not known to me. Still, the idea is the same. Create a recursive function that processes the parent, then calls itself on each of the children.
I'm sure there's a more generic way to do this using templates, that parameterizes the function, which would mean you don't have to write a separate walk function for every distinct function prototype on fn . Maybe that's an exercise you could undertake to help improve your understanding of templates, and other C++ facilities.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
modified 13hrs ago.
|
|
|
|
|
Thank you.
I was hoping to build on my current knowledge and working code , regardless if it is standard or not.
I am looking into this
QTreeWidgetItemIterator<QAction*> it(parent<QAction*>(this));
and have two issues with it
I still cannot access the object "parent" and it looks as this class expects
tree widget to iterate.
Moore RTFM.
|
|
|
|
|
Salvatore Terress wrote: Moore RTFM
Correct
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
It worked...
I did save you a time to write FOUR letters...
Maybe I should end my post instead of
Cheers
( I hope you take this post as a joke ...good night from Huston )
|
|
|
|
|
I am trying to learn using templates and run into this TWO versions of C++ code.
Both works as expected, however,....
The first version compiles , bur WON'T work until
<qaction *="">
is added to "findChildren".
Would appreciate some (REAL) comments
variation of "RTFM" not necessary.
QString textMatch = "tile";
QList<QAction*> pTEST = parent->findChildren<QAction *>();
for (auto *action : pTEST)
{
text = action->objectName();
if(text.contains(textMatch))
{
action->trigger();
text += " match ";
qDebug().noquote() << text;
break;
}
}
const auto actionList = parent->findChildren<QAction *>();
for (auto *action : actionList)
{
text = action->objectName();
if(text.contains(textMatch))
{
action->trigger();
qDebug().noquote() << text;
break;
}
}
|
|
|
|
|
1. This has nothing to do with templates.
2. If you change the word pTEST in the first example to actionList , you will see that they are both exactly the same. Barring, of course the line:
text += " match ";
which is not present in the second sample.
And since the findChildren function returns a list of QAction* items, it matters not whether you specify it explicitly, or leave the compiler to infer it from the context.
|
|
|
|
|
VOLUNTARILY REMOVED
modified 2 days ago.
|
|
|
|
|
|
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 30-Apr-24 11:57am.
|
|
|
|
|
use imgur.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
And how about copy/paste the eliable code snippet together with "debug assertion failed" message text?
|
|
|
|
|
Is here somebody ON THIS forum to help me navigate - using C++ code - thru the debug message?
and using Qt?
I am NOT going to post more just to get " do not post Qt questions here ..." ,
hence wasting my time.
|
|
|
|
|
Salvatore Terress wrote: to help me navigate - using C++ code - thru the debug message?
Please, define "navigate - using C++ code - thru the debug message". ![Cool | :cool:](https://codeproject.freetls.fastly.net/script/Forums/Images/smiley_cool.gif)
|
|
|
|
|
Please answer FIRST
are you willing to help using Qt ?
If not
thanks
|
|
|
|
|
Salvatore Terress wrote: are you willing to help using Qt ?
If not
thanks
You are welcome! ![Suspicious | :suss:](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_suss.gif)
|
|
|
|
|