Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connect setMode() to a button

Connect setMode() to a button

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 758 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Greedan97
    wrote on last edited by
    #1

    Hi, this is my first post,I were progamming on qt for school,and I have to connect the setMode of a QLCDNumber to a button,
    What is wrong?

    (QLCDNumber *D;
    D=new QLCDNumber(8);)

    @connect("button", SIGNAL(clicked()), D, SLOT(setMode(Hex)));@

    I tried to write D->Value(), but..nothing..

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to devnet.

      That's not how it works. the first argument is not a string, it's an object pointer.
      SLOT is a text macro. You can't pass arguments at connect site with it.

      If you're using a c++11 compiler the simplest would be to connect a lambda:
      @
      //D is a terrible name so I'll just use something else
      QLCDNumber* lcd = new QLCDNumber(8);
      QPushButton* button = new QPushButton("Set hex mode");

      connect(button, &QPushButton::clicked, ={
      lcd->setMode(QLCDNumber::Hex);
      });
      @
      If you can't use c++11 then you need to create a function in your class and connect to that.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved