Skip to content

C++ Gurus

The forum for all discussions in C++ land.
1.3k Topics 8.5k Posts
  • connect won't...

    Unsolved
    5
    0 Votes
    5 Posts
    426 Views
    Axel SpoerlA

    @AnneRanch said in connect won't...:

    Here's your problem:

    QObject::connect(QAction, MainWindow_Bluetooth): invalid nullptr parameter

    The array you use for the connect statement isn't populated properly.
    At this location:

    connect(subAction[index_sub] , &QAction::triggered, this , [=]() { this->process_TEST() ;});

    ...you have a nullptr in subAction[index_sub].

    That's probably a result of the somewhat unusual approach to store actions in an array.

  • Synthesis of == from operator<=>

    Solved
    4
    0 Votes
    4 Posts
    408 Views
    A

    @SGaist Many thanks, I must have missed that one!

  • Please help with actual C++ code

    Unsolved
    25
    0 Votes
    25 Posts
    2k Views
    JonBJ

    @AnneRanch

    but I am unable to add "check box" to any of them

    QAction *action = submenu[index]->addAction("Some text"); action->setCheckable(true);

    adds an action with text Some text and sets it to have a checkbox.

  • Main menu set with submenu - triggering issue

    Unsolved
    5
    0 Votes
    5 Posts
    470 Views
    JonBJ

    @AnneRanch
    You may have been trying to do what I did some time ago, but discovered it does not work so is not allowed in Qt. If you have a sub-menu on a menu --- i.e. the menu has that > you click on to "slide out" the sub-menu --- then although Qt allows you also put a checkbox on the parent menu item which has the > slide-out it actually does not work correctly for checking the box, and cannot be made to do so. Do not try to put a checkbox on a menu item which has a child menu slide-out.

  • Passing a value to slot...

    Unsolved
    18
    0 Votes
    18 Posts
    2k Views
    JonBJ

    @AnneRanch said in Passing a value to slot...:

    Minor detail;
    you example is missing the closing
    "}" - but the compiler catches that, no big deal.

    You are correct, my bad. I just type these examples in, my eyesight is not what it used to be! (I believe) I have corrected both my previous posts to have that missing }.

  • Whar is this error saying?

    Unsolved
    6
    0 Votes
    6 Posts
    438 Views
    J.HilkJ

    @AnneRanch said in Whar is this error saying?:

    Thanks , I wad actually triggering on wrong action before. I guess I will never know why I how to read the "() " error to correct my code.

    The compiler is actually exactly telling you why it has a problem with the (missing) brackets, I'll quote the part:

    cpp-compiler said in mainwindow_Bluetooth.cpp

    error: expected '(' for function-style cast or type construction

    it thinks your bool is an attempt of you to cast something to an boolean and it thinks the silly programmer forgot to add the bracket and the actual variable that is supposed to be cast.

    something like this:

    int a = 0; auto b = bool(a);

    or in your particular case:

    void triggered(bool variable) { qDebug() << variable } .... int a = 0; triggered(bool(a));

    The compiler doesn't know that function style cast do only the other people, true c++ programers don't use it at all.

  • QMenu . QAction how can I add "checked "?

    Unsolved
    7
    0 Votes
    7 Posts
    469 Views
    A

    FINALLY...

    here a current WORKING as expected - both menu and submenu have check boxes and only main menu has "arrows"....

    Unless there are objections I am going to clean up the worthless code...

    Thanks foe sticking with the problem...

    mainAction[index_main] = m_ui->menuWindow_cpntrol->addAction(list[ index_main] + " #" + QString::number( index_main)); mainAction[index_main]->setCheckable(true); //adds arrows mainAction[index_main]->setMenu(tempmenu); subAction[index_main] = tempmenu->addAction(list_hcitool[ index_main] + " #" + QString::number( index_main)); subAction[index_main]->setCheckable(true);
  • QMenu C++ code help

    Unsolved
    6
    0 Votes
    6 Posts
    437 Views
    JonBJ

    @AnneRanch said in QMenu C++ code help:

    That is the issue - how to change "checkable" property when there is access only to QMenu.

    That is what you wrote. So I took the time to answer it exactly.

    You cannot get directly from a QAction * to the QMenu you put it on, unlike the other way round which you asked and is answered. However, you can use QList<QObject *> QAction::associatedObjects() const from a QAction and you should find the QMenu it has been added to among them. And you add submenus to a menu. Which answers the new question.

  • QMenu - submenu arrow removal

    Solved
    6
    0 Votes
    6 Posts
    484 Views
    Axel SpoerlA

    @AnneRanch said in QMenu - submenu arrow removal:

    my OS is Linux

    Same here.
    Start spectacle, define a delay of e.g. 10s, choose a rectangle or select "Active Window".
    Then you have 10s to bring the menu up and keep it.
    But I assume you won't do it anyway, as usual.

  • What "Parentheses" am I missing ?

    Unsolved
    4
    0 Votes
    4 Posts
    297 Views
    Axel SpoerlA

    @AnneRanch
    The recommended way is:
    connect(subAction[index], &yourClass::triggered, this, &thisClass::testSlot);

  • This topic is deleted!

    Unsolved
    2
    0 Votes
    2 Posts
    17 Views
  • Add to mdiArea using C++ code and QTDesigner

    Solved
    1
    0 Votes
    1 Posts
    158 Views
    No one has replied
  • Process Protection

    Unsolved
    12
    0 Votes
    12 Posts
    1k Views
    TomZT

    @Chris-Kawa said in Process Protection:

    If what you're saying was universal the entire gaming industry wouldn't exist and wouldn't be the biggest entertainment medium in the world as it is.

    I'd like to point out that there is no conflict in that world and what I wrote.

    See this description; https://www.theverge.com/2021/9/23/22690670/epic-eac-anti-cheat-linux-valve-steam-deck-support-games

    EasyAntiCheat is a company that doesn't focus on process protection in the way that OP asked. For starters it requires kernel support.

  • 0 Votes
    7 Posts
    598 Views
    JoeCFDJ

    @Chris-Kawa Unluckily, not, Chris. A, B and X are downloaded. If I can rebuild A and B, I will be able to build A, B and X to FOO easily. One way out may be to exclude X from the build with '-Wl,--exclude-libs, X', but break X and add its obj files to FOO while keeping A and B

  • 0 Votes
    2 Posts
    442 Views
    JonBJ

    @Sachin-Bhatt
    I had to look up what "dynamic programming" is! They like their labels for things, don't they?

    Am I missing something, or is this real easy? You start by setting a variable for the longest subsequence to 0. You count from left to right while the numbers increase. So for 10, 22 and then 9 the longest so far is 2 (10, 22), terminated by 9 (because it is less than the preceding 22). You note that 2 is the longest so far, because it is more than 0, and so update the count variable. You know that you can resume looking from the 9. You encounter 9, 33 and then 21, 50, both terminated by smaller numbers, and those are also of length 2, no better then before. Finally you meet 41, 60, 80, terminated by end of input, that is length 3, and so is the highest. So that is what you return....

  • 0 Votes
    3 Posts
    362 Views
    TomZT

    @prasad2023 said in Cross platform compatible GUI application with C++ core logic:

    Are qt gui and c++ backend are right technologies to develop such application?

    Obviously, you will get a "yes" here.

    There is a very large number of applications written using Qt that are similar to what you describe.
    With "similar" I don't specifically mean trading applications, I mean professional desktop applications that use high-volumes of data and aim at a great user interface.

    @prasad2023 said in Cross platform compatible GUI application with C++ core logic:

    afaik, qt apis are wrappers around native os apis. will it impact performance?

    This is not a good description. Qt is a toolkit and covers a LOT of ground and provides a very large number of features.
    Any other toolkits, including the ones from Windows or Mac will basically have the same approach that Qt has for most of these features.
    Therefore it won't be slower than those.

    The term "wrapped" I have mostly seen used for widgets. The point there is that a Qt app can look identical to a native Windows or Mac application. If you so choose. I don't think you need to worry about that being slow.

    @prasad2023 said in Cross platform compatible GUI application with C++ core logic:

    is there any alternative for c++ for this requirement.

    I don't think there is anything out there that will be good enough for such an application.

  • passing Q_GADGET object as argument

    Unsolved
    7
    0 Votes
    7 Posts
    509 Views
    mzimmersM

    @Axel-Spoerl no, not at all. Maybe some code will help. I have a struct:

    struct Equipment { Q_GADGET QML_STRUCTURED_VALUE QML_VALUE_TYPE(equipment) ...

    and I maintain a list of these in a model.

    In my QML, I have a ListView that accesses the model, and furnishes the contents to a delegate that eventually gets down to:

    equipmentModel.processSpaceAssignment(vspInModel, spaceUuid, checked)

    where vspInModel is an instance of a subclass of Equipment. There's some rather complex work that needs to be done, so I didn't want to try to implement it in JS. The C++ function signature is:

    bool EquipmentModel::processSpaceAssignment(Equipment equipment, QUuid spaceUuid, bool add)

    So, my original question was, is this equipment/vsp object passed by value in this case?

  • single function to accept different parameter types

    Solved
    23
    0 Votes
    23 Posts
    2k Views
    mzimmersM

    One of my co-workers came up with this workaround:

    // would entail one of these routines for each subclass, // but they would all do the exact same thing. void EquipmentModel::sendPatchRequest(const Vsp &equipment) { sendBaseRequest(equipment); } void EquipmentModel::sendBaseRequest(const Equipment &equipment) { if (m_qnrPatch == nullptr) { int i = getIndex(equipment.m_uuid); if (i == NOT_IN_LIST) { continue; } Equipment &listEntry = *(*m_list)[i]; equipment.addPatchFields(listEntry, qjo, rolesToKeys); // goes to subclass function. ...

    It works. Unless someone comes up with a better idea, I'll close out this topic. Thanks for all the suggestions...

  • 0 Votes
    4 Posts
    500 Views
    mzimmersM

    @Sachin-Bhatt said in Understanding the Code: Differentiating Between Process and Program in C++:

    Can you explain how this C++ code represents both a process and a program?

    To add to what the others said, code is never a process. Source code like yours is built (compiled and linked) into a program (something that can be run). A process is something the OS furnishes for your program is built.

    It might help to think of it this way: if all computers in the world ran the same OS, you could build your program, and distribute to millions of people everywhere. Every time they run it, they create a process on their system, but it's the same program (the bits in the executable file you distribute are identical).

    Hope this helps a little...

  • trying to understand smart pointers...

    Solved
    30
    0 Votes
    30 Posts
    3k Views
    mzimmersM

    @Chris-Kawa if I make pEquipment local to this function, then I can't use it in my insertRows() call. That's why I made it a member of the class. I can still use your technique of accessing list elements with a conventional pointer, though...thoughts?

    Based on what I've shown about my app, should I even be using unique_ptrs or shared_ptrs in my list/vector?