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. How to call public QString that have declared in MainWindow.h from other form?

How to call public QString that have declared in MainWindow.h from other form?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 823 Views 2 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.
  • A Offline
    A Offline
    aysenur
    wrote on last edited by
    #1

    Hello ,
    I have declared a string in the public of mainwindow.h and initialized in mainwindow.cpp. I want to call this string from other source file which is a qwidget. When I call this string program goes to infinite loop. How can I solve this? Thank you in advance.

    K 1 Reply Last reply
    0
    • A aysenur

      Hello ,
      I have declared a string in the public of mainwindow.h and initialized in mainwindow.cpp. I want to call this string from other source file which is a qwidget. When I call this string program goes to infinite loop. How can I solve this? Thank you in advance.

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @aysenur

      You need to give some source lines of your code on how you access the string and what you are doing with it.

      Otherwise you should use the debugger and try to find the condition of your endless loop. Most likely it has nothing to with the string.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aysenur
        wrote on last edited by
        #3

        Thank you for your reply. I need a global string variable in MainWindow. I have declared it under the public of mainwindow.h code is:
        public:
        QString mystring;
        I have assigned the selected file name under button click to this variable. In the Mainwindow there is an object which shows the stl file. This part has another cpp file and I need to call declared string form this .cpp. Is it possible? When I add #include "mainwindow.h" header I can access mystring from this .cpp class but program goes to infinite loop.
        Code :MainWindow a;
        QFile file(a.deneme);

        1 Reply Last reply
        0
        • artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #4

          Hi,
          I would suggest different approach: declare the QString in target cpp that holds the file name (private), along with public slot that acts as a setter.
          Then, in MainWindow, connect the QPushButton::clicked(signal) (or create your own that would pass the desired value to the slot).

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          2

          • Login

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