QT Get the list all button











up vote
-5
down vote

favorite












QObjectList list =children() ;
qDebug() << list.length() << endl;
QPushButton *b;
foreach (QObject *obj, list)
{
b = qobject_cast<QPushButton*>(obj);
if(b)
{
PushButtonStr.append( b->text());
qDebug() << b->text() << endl;
}
}


In Widget::Widget can get the list all button,but In my class can't get the button?










share|improve this question




















  • 3




    You question is unclear, please check how to ask a good question.
    – Shayn
    Nov 11 at 11:22










  • QT get the list all Qpushbutton?
    – user10635895
    Nov 11 at 11:28












  • Hi there, welcome to SO. As much as we would like to help, it is difficult to understand what your question is trying to ask. You've provided code... but what does it do and what is its connection to the problem? What is Widget::Widget? It doesn't look like a QWidget... What does list all button mean? What is your class? Please don't assume we know everything and please make an attempt to clarify your question...
    – TrebuchetMS
    Nov 11 at 11:35












  • sorry,my English is very poor , I want to get all the QpushButton controls on the UI, "void PLC::SearchControl()" This is a PLC Class I wrote, in this class qDebug() << list.length() << endl; The result is 0, but the UI There are 5 buttons on it
    – user10635895
    Nov 11 at 12:00










  • Chinese:我想用我自己写的一个PLC类,来遍历UI界面上的所有按钮控件,代码上面已经列出,在PLC类里面直接children(),不能得到UI上的按钮控件,所以会返回0,放在Widget的构造函数里面是能正常遍历所有按钮控件的。问题:我在自己的类中如何去获取UI界面上的按钮控件
    – user10635895
    Nov 11 at 12:06

















up vote
-5
down vote

favorite












QObjectList list =children() ;
qDebug() << list.length() << endl;
QPushButton *b;
foreach (QObject *obj, list)
{
b = qobject_cast<QPushButton*>(obj);
if(b)
{
PushButtonStr.append( b->text());
qDebug() << b->text() << endl;
}
}


In Widget::Widget can get the list all button,but In my class can't get the button?










share|improve this question




















  • 3




    You question is unclear, please check how to ask a good question.
    – Shayn
    Nov 11 at 11:22










  • QT get the list all Qpushbutton?
    – user10635895
    Nov 11 at 11:28












  • Hi there, welcome to SO. As much as we would like to help, it is difficult to understand what your question is trying to ask. You've provided code... but what does it do and what is its connection to the problem? What is Widget::Widget? It doesn't look like a QWidget... What does list all button mean? What is your class? Please don't assume we know everything and please make an attempt to clarify your question...
    – TrebuchetMS
    Nov 11 at 11:35












  • sorry,my English is very poor , I want to get all the QpushButton controls on the UI, "void PLC::SearchControl()" This is a PLC Class I wrote, in this class qDebug() << list.length() << endl; The result is 0, but the UI There are 5 buttons on it
    – user10635895
    Nov 11 at 12:00










  • Chinese:我想用我自己写的一个PLC类,来遍历UI界面上的所有按钮控件,代码上面已经列出,在PLC类里面直接children(),不能得到UI上的按钮控件,所以会返回0,放在Widget的构造函数里面是能正常遍历所有按钮控件的。问题:我在自己的类中如何去获取UI界面上的按钮控件
    – user10635895
    Nov 11 at 12:06















up vote
-5
down vote

favorite









up vote
-5
down vote

favorite











QObjectList list =children() ;
qDebug() << list.length() << endl;
QPushButton *b;
foreach (QObject *obj, list)
{
b = qobject_cast<QPushButton*>(obj);
if(b)
{
PushButtonStr.append( b->text());
qDebug() << b->text() << endl;
}
}


In Widget::Widget can get the list all button,but In my class can't get the button?










share|improve this question















QObjectList list =children() ;
qDebug() << list.length() << endl;
QPushButton *b;
foreach (QObject *obj, list)
{
b = qobject_cast<QPushButton*>(obj);
if(b)
{
PushButtonStr.append( b->text());
qDebug() << b->text() << endl;
}
}


In Widget::Widget can get the list all button,but In my class can't get the button?







c++ qt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 11:23









Mat

163k27306338




163k27306338










asked Nov 11 at 11:19









user10635895

1




1








  • 3




    You question is unclear, please check how to ask a good question.
    – Shayn
    Nov 11 at 11:22










  • QT get the list all Qpushbutton?
    – user10635895
    Nov 11 at 11:28












  • Hi there, welcome to SO. As much as we would like to help, it is difficult to understand what your question is trying to ask. You've provided code... but what does it do and what is its connection to the problem? What is Widget::Widget? It doesn't look like a QWidget... What does list all button mean? What is your class? Please don't assume we know everything and please make an attempt to clarify your question...
    – TrebuchetMS
    Nov 11 at 11:35












  • sorry,my English is very poor , I want to get all the QpushButton controls on the UI, "void PLC::SearchControl()" This is a PLC Class I wrote, in this class qDebug() << list.length() << endl; The result is 0, but the UI There are 5 buttons on it
    – user10635895
    Nov 11 at 12:00










  • Chinese:我想用我自己写的一个PLC类,来遍历UI界面上的所有按钮控件,代码上面已经列出,在PLC类里面直接children(),不能得到UI上的按钮控件,所以会返回0,放在Widget的构造函数里面是能正常遍历所有按钮控件的。问题:我在自己的类中如何去获取UI界面上的按钮控件
    – user10635895
    Nov 11 at 12:06
















  • 3




    You question is unclear, please check how to ask a good question.
    – Shayn
    Nov 11 at 11:22










  • QT get the list all Qpushbutton?
    – user10635895
    Nov 11 at 11:28












  • Hi there, welcome to SO. As much as we would like to help, it is difficult to understand what your question is trying to ask. You've provided code... but what does it do and what is its connection to the problem? What is Widget::Widget? It doesn't look like a QWidget... What does list all button mean? What is your class? Please don't assume we know everything and please make an attempt to clarify your question...
    – TrebuchetMS
    Nov 11 at 11:35












  • sorry,my English is very poor , I want to get all the QpushButton controls on the UI, "void PLC::SearchControl()" This is a PLC Class I wrote, in this class qDebug() << list.length() << endl; The result is 0, but the UI There are 5 buttons on it
    – user10635895
    Nov 11 at 12:00










  • Chinese:我想用我自己写的一个PLC类,来遍历UI界面上的所有按钮控件,代码上面已经列出,在PLC类里面直接children(),不能得到UI上的按钮控件,所以会返回0,放在Widget的构造函数里面是能正常遍历所有按钮控件的。问题:我在自己的类中如何去获取UI界面上的按钮控件
    – user10635895
    Nov 11 at 12:06










3




3




You question is unclear, please check how to ask a good question.
– Shayn
Nov 11 at 11:22




You question is unclear, please check how to ask a good question.
– Shayn
Nov 11 at 11:22












QT get the list all Qpushbutton?
– user10635895
Nov 11 at 11:28






QT get the list all Qpushbutton?
– user10635895
Nov 11 at 11:28














Hi there, welcome to SO. As much as we would like to help, it is difficult to understand what your question is trying to ask. You've provided code... but what does it do and what is its connection to the problem? What is Widget::Widget? It doesn't look like a QWidget... What does list all button mean? What is your class? Please don't assume we know everything and please make an attempt to clarify your question...
– TrebuchetMS
Nov 11 at 11:35






Hi there, welcome to SO. As much as we would like to help, it is difficult to understand what your question is trying to ask. You've provided code... but what does it do and what is its connection to the problem? What is Widget::Widget? It doesn't look like a QWidget... What does list all button mean? What is your class? Please don't assume we know everything and please make an attempt to clarify your question...
– TrebuchetMS
Nov 11 at 11:35














sorry,my English is very poor , I want to get all the QpushButton controls on the UI, "void PLC::SearchControl()" This is a PLC Class I wrote, in this class qDebug() << list.length() << endl; The result is 0, but the UI There are 5 buttons on it
– user10635895
Nov 11 at 12:00




sorry,my English is very poor , I want to get all the QpushButton controls on the UI, "void PLC::SearchControl()" This is a PLC Class I wrote, in this class qDebug() << list.length() << endl; The result is 0, but the UI There are 5 buttons on it
– user10635895
Nov 11 at 12:00












Chinese:我想用我自己写的一个PLC类,来遍历UI界面上的所有按钮控件,代码上面已经列出,在PLC类里面直接children(),不能得到UI上的按钮控件,所以会返回0,放在Widget的构造函数里面是能正常遍历所有按钮控件的。问题:我在自己的类中如何去获取UI界面上的按钮控件
– user10635895
Nov 11 at 12:06






Chinese:我想用我自己写的一个PLC类,来遍历UI界面上的所有按钮控件,代码上面已经列出,在PLC类里面直接children(),不能得到UI上的按钮控件,所以会返回0,放在Widget的构造函数里面是能正常遍历所有按钮控件的。问题:我在自己的类中如何去获取UI界面上的按钮控件
– user10635895
Nov 11 at 12:06














1 Answer
1






active

oldest

votes

















up vote
0
down vote













try to use



QList<QPushButton*> PbList = findChildren<QPushButton*>();


if you are inside a class derived from QObject, like i.e. QWidget



Qt doc






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248197%2fqt-get-the-list-all-button%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    try to use



    QList<QPushButton*> PbList = findChildren<QPushButton*>();


    if you are inside a class derived from QObject, like i.e. QWidget



    Qt doc






    share|improve this answer



























      up vote
      0
      down vote













      try to use



      QList<QPushButton*> PbList = findChildren<QPushButton*>();


      if you are inside a class derived from QObject, like i.e. QWidget



      Qt doc






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        try to use



        QList<QPushButton*> PbList = findChildren<QPushButton*>();


        if you are inside a class derived from QObject, like i.e. QWidget



        Qt doc






        share|improve this answer














        try to use



        QList<QPushButton*> PbList = findChildren<QPushButton*>();


        if you are inside a class derived from QObject, like i.e. QWidget



        Qt doc







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 at 19:22

























        answered Nov 13 at 19:01









        claude joliat

        347




        347






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248197%2fqt-get-the-list-all-button%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine