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. Qt: Global String Calling Issue
Qt 6.11 is out! See what's new in the release blog

Qt: Global String Calling Issue

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 323 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.
  • E Offline
    E Offline
    elfenliedtopfan5
    wrote on last edited by
    #1

    Ok i am new to QT and been playing around and watching tutorials but i having issues reverencing a string i want to make global,

    here is my .H

    #ifndef ELFENLIEDTOPFAN5RES_H
    #define ELFENLIEDTOPFAN5RES_H
    #include <QString>
    
    
    class ELFENLIEDTOPFAN5RES
    {
    public:
    ELFENLIEDTOPFAN5RES();
    static QString BO3_Path;
    };
    
    
    
    
    #endif // ELFENLIEDTOPFAN5RES_H
    

    and here is the cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QMessageBox>
    #include <QStatusBar>
    #include "elfenliedtopfan5Res.h"
    
    
    ELFENLIEDTOPFAN5RES::ELFENLIEDTOPFAN5RES()
    {
        ELFENLIEDTOPFAN5RES::BO3_Path = (QString(getenv("TA_GAME_PATH")).replace('\\', '/'));
    
    }
    
    
    MainWindow::MainWindow(QWidget *parent)
    
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
    }
    
    
    MainWindow::~MainWindow()
    {
    
        delete ui;
        //const QString elfenliedtopfan5Res::BO3_PATH = (QString(getenv("TA_GAME_PATH")).replace('\\', '/'));
    }
    
    
    
    void MainWindow::on_pushButton_clicked()
    {
        QString elfen2 = ELFENLIEDTOPFAN5RES::BO3_Path;
       QMessageBox::information(this,"title",elfen2);
    }
    

    this is the error it throws,
    mainwindow.cpp:-1: error: undefined reference to `ELFENLIEDTOPFAN5RES::BO3_Path'

    but unsure of why its doing this i have tried multiple things and looked on loads of global string setups but still no avail
    sorry if its a noob question
    thank you for reading
    elfenliedtopfan5

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Basic c++ - a static variable needs to be properly initialized. You only declared that there is a static variable but did not define it.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      E 1 Reply Last reply
      4
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Move that line out of the constructor. Initializing a static class variable is not done there.

        By the way, Qt provides functions to get environment variables.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • Christian EhrlicherC Christian Ehrlicher

          Basic c++ - a static variable needs to be properly initialized. You only declared that there is a static variable but did not define it.

          E Offline
          E Offline
          elfenliedtopfan5
          wrote on last edited by
          #4

          @Christian-Ehrlicher Thank you sorry i am really new to QT and c++ is not my native language c# is so get little confused but than you for reply :)

          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