zoukankan      html  css  js  c++  java
  • c++ 入门

      •  
        Chris Kawa Moderators

        Gosh, you really should start with some simple c++ before using Qt. These are fundamental c++ constructs. Maybe a book or a tutorial on classes first?
        I'm not trying to be harsh. It would make a lot of stuff easier for you as you're clearly struggling with basic concepts of what is a class, an instance, a pointer etc. and trying things until it works without understanding how and why it works. Get the basics right and it will all become trivial.

        @
        //this is a class method. works ok because
        //hide() in his context is a member method of QMainWindow,
        //which is the base class of login
        void login::on_pushButton_login_clicked(){
        hide();
        }

        //this is a free standing function unrelated to any class or instance.
        //hide() is meaningless in this context. Hide what? what is hide()?
        //there's no standing function named hide().
        void hidethis(){
        hide();
        }

        //are you misssing a declaration in the header?
        //if declared and called correctly this will work
        void login::hidethis(){
        hide();
        }

        //login_win is a local variable.
        //you are trying to hide a new window that is not even shown
        //this is NOT hiding the instance you are calling it from
        //also you're creating a memory leak by allocating local_win and never releasing it
        login *login_win;
        login_win = new login();
        login_win->hide();
        @


      • babuschkainyouface

        hi chris,
        i am new to QT and c++ but i thought programming something you are interested in is possibly the best way to learn it.
        sorry for getting on your nerves - will repeat the basic concepts again

        thanks for your explanation - i hope i will work it out


      • Chris Kawa Moderators

        I'm not nervous, no worry. I just seem that way ;)

        Learning by doing is a great thing, but you don't start by building a car. First learn how an engine or the breaks work and build your way up. Otherwise you will just struggle a lot. It's hard to do the hard stuff without first knowing the easy stuff ;)

        First learn what's the difference between a method and a function, between a class and an instance, basics of OO like inheritance and polymorphism. What is a scope of a variable/member/function/method. Write some simple programs using these (without Qt).
        Then you can start with some basic concepts of Qt like event loop, signals/slots and ui. From there sky is the limit, but it will be easier and more natural to see how one thing is used to do another. If you jump at it and try to do everything at once it will just seem hard and chaotic and you will need to ask about every single thing, which you could easily figure out yourself or by reading docs otherwise.

        There's a c++ section on this forum if you need any help with these topics and there's a bunch of examples shipped with Qt.
        Good luck.

  • 相关阅读:
    HDU1255覆盖的面积
    B. An express train to reveries
    Long Long Message(后缀数组)
    Longest Common Substring(最长公共子序列)
    最长上升子序列(NlogN)总结
    bzoj 1500 维修数列
    HDU 6357 Hills And Valleys
    牛客暑假多校第六场 I Team Rocket
    HDU 6346 整数规划 二分图匹配最优解
    牛客暑假多校第五场 I vcd
  • 原文地址:https://www.cnblogs.com/liujx2019/p/14331406.html
Copyright © 2011-2022 走看看